package com.zjdiepu.www.hzicbc.biz.impl;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import javax.annotation.Resource;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.jexl2.UnifiedJEXL.Exception;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.diepu.www.client.hzicbc.proxy.enums.CertificatesType;
import com.diepu.www.client.hzicbc.proxy.enums.FileListType;
import com.diepu.www.client.hzicbc.proxy.enums.PicIdType;
import com.diepu.www.client.hzicbc.proxy.enums.ReturnCodePrefixType;
import com.diepu.www.client.hzicbc.proxy.request.PublicRequest;
import com.diepu.www.client.hzicbc.proxy.request.applyDiviGeneral.ApplyDiviGeneralBaseInfo;
import com.diepu.www.client.hzicbc.proxy.request.applyDiviGeneral.ApplyDiviGeneralBusiInfo;
import com.diepu.www.client.hzicbc.proxy.request.applyDiviGeneral.ApplyDiviGeneralRequest;
import com.diepu.www.client.hzicbc.proxy.request.applyStatus.ApplyStatusRequest;
import com.diepu.www.client.hzicbc.proxy.request.common.CarInfo;
import com.diepu.www.client.hzicbc.proxy.request.common.CustomerInfo;
import com.diepu.www.client.hzicbc.proxy.request.common.DiviInfo;
import com.diepu.www.client.hzicbc.proxy.request.common.PicInfo;
import com.diepu.www.client.hzicbc.proxy.request.creditCardApply.CreditCardApplyInfo;
import com.diepu.www.client.hzicbc.proxy.request.creditCardApply.CreditCardApplyRequest;
import com.diepu.www.client.hzicbc.proxy.request.creditCardApply.LoanInfo;
import com.diepu.www.client.hzicbc.proxy.request.creditStatus.CreditStatusRequest;
import com.diepu.www.client.hzicbc.proxy.request.fileDownload.FileDownloadInfo;
import com.diepu.www.client.hzicbc.proxy.request.fileDownload.FileDownloadRequest;
import com.diepu.www.client.hzicbc.proxy.request.multimediaupload.MultimediauploadInfo;
import com.diepu.www.client.hzicbc.proxy.request.multimediaupload.MultimediauploadRequest;
import com.diepu.www.client.hzicbc.proxy.response.HzicbcBaseResponse;
import com.diepu.www.client.hzicbc.proxy.response.PublicResponse;
import com.diepu.www.client.hzicbc.proxy.response.applyStatus.ApplyStatusInfo;
import com.diepu.www.client.hzicbc.proxy.response.creditStatus.CreditStatusInfo;
import com.diepu.www.client.partner.proxy.request.ApplyDiviBackProxyRequest;
import com.diepu.www.client.partner.proxy.request.ApplyDiviStatusProxyRequest;
import com.diepu.www.client.partner.proxy.request.OpenCardbackReasonRequest;
import com.diepu.www.client.partner.proxy.request.UpdateDownloadStatusRequest;
import com.diepu.www.client.partner.proxy.request.UpdatePushStatusRequest;
import com.diepu.www.client.partner.xhh.enums.PartnerErrorCode;
import com.diepu.www.client.proxy.hzicbc.response.handPic.HandPicDetail;
import com.diepu.www.client.proxy.hzicbc.response.handPic.HandPicResponse;
import com.diepu.www.client.proxy.partner.request.own.DiepuYwOpenCardHzicbcRequest;
import com.zjdiepu.www.base.enums.status.ApplyDiviStatus;
import com.zjdiepu.www.base.enums.status.DownloadStatus;
import com.zjdiepu.www.base.enums.status.DpStatus;
import com.zjdiepu.www.base.enums.status.HzicbcApplyDiviStatus;
import com.zjdiepu.www.base.enums.status.PushStatus;
import com.zjdiepu.www.base.enums.type.AttachmentLabel;
import com.zjdiepu.www.base.enums.type.AttachmentSort;
import com.zjdiepu.www.base.enums.type.CreditPeopleType;
import com.zjdiepu.www.base.enums.type.OperateType;
import com.zjdiepu.www.common.consts.SystemConsts;
import com.zjdiepu.www.common.util.DateUtil;
import com.zjdiepu.www.enums.StatusEventLog;
import com.zjdiepu.www.enums.TransferHandleStatus;
import com.zjdiepu.www.enums.TransferModeID;
import com.zjdiepu.www.hzicbc.biz.IHzicbcProxyService;
import com.zjdiepu.www.proxy.biz.impl.BaseProxyService;
import com.zjdiepu.www.proxy.biz.transfer.INewTransaction;
import com.zjdiepu.www.proxy.biz.transfer.ITransferDzApplyDiviService;
import com.zjdiepu.www.proxy.biz.transfer.ITransferYwInterviewInfoService;
import com.zjdiepu.www.proxy.model.dto.own.SysUserProxy;
import com.zjdiepu.www.proxy.model.dto.transfer.TransferDzApplyDivi;
import com.zjdiepu.www.proxy.model.dto.transfer.TransferLogs;
import com.zjdiepu.www.proxy.model.dto.transfer.TransferLogsSub;
import com.zjdiepu.www.proxy.model.dto.transfer.TransferOtherAttachments;
import com.zjdiepu.www.proxy.model.dto.transfer.TransferYwBusinessBuyer;
import com.zjdiepu.www.proxy.model.dto.transfer.TransferYwBusinessCar;
import com.zjdiepu.www.proxy.model.dto.transfer.TransferYwBusinessLoan;
import com.zjdiepu.www.proxy.model.dto.transfer.TransferYwInterviewInfo;
import com.zjdiepu.www.proxy.model.dto.transfer.TransferYwOpenCardHzicbc;
import com.zjdiepu.www.proxy.model.dto.transfer.TransferYwOpenCardHzicbcSub;
import com.zjdiepu.www.proxy.model.dto.transfer.TransferYwOrdernoBank;
import com.zjdiepu.www.proxy.model.ext.transfer.TransferOtherAttachmentsExt;
import com.zjdiepu.www.security.base.enums.ResultCode;
import com.zjdiepu.www.security.exception.BasePartnerException;
import com.zjdiepu.www.security.exception.ParamException;
import com.zjdiepu.www.security.exception.ProgramException;
import com.zjdiepu.www.security.exception.SystemException;
import com.zjdiepu.www.service.partner.IDiepuService;
import com.zjdiepu.www.util.ExceptionHelper;
/**
 * 调用杭州工商银行接口
 * @author xiongxiaotun
 */
@Service
public class HzicbcProxyServiceImpl extends BaseProxyService implements IHzicbcProxyService {
	private Logger logger = LoggerFactory.getLogger(HzicbcProxyServiceImpl.class);
	
	private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
	@Resource
	private ITransferDzApplyDiviService transferDzApplyDiviService;
	@Resource
	private INewTransaction newTransaction;
	@Resource
	private ITransferYwInterviewInfoService transferYwInterviewInfoService;
	@Resource
	private IDiepuService diepuService;
	
	@Override
	public boolean saveSynPushStatus(String ordeRno, String busiId) {
		if(!StringUtils.isNoneBlank(ordeRno, busiId)) {
			logger.error("同步推送状态，参数为空，ordeRno：{}， busiId :{}.", ordeRno, busiId);
			return true;
		}
		try {
			TransferYwInterviewInfo transferYwInterviewInfo = new TransferYwInterviewInfo();
			transferYwInterviewInfo.setDpStatus(DpStatus.NORMAL.getCode());
			transferYwInterviewInfo.setBusiId(busiId);
			transferYwInterviewInfo = transferYwInterviewInfoService.selectRefined(transferYwInterviewInfo);
			if(null == transferYwInterviewInfo) {
				logger.error("HzicbcProxyServiceImpl.saveSynPushStatus. 面签信息记录为空，busiId ： {}.", busiId);
				throw new BasePartnerException(PartnerErrorCode.RECORD_INTERVIEW_MISSING.getCode(), PartnerErrorCode.RECORD_INTERVIEW_MISSING.getName());
			}
			String id = transferYwInterviewInfo.getId();
			
			UpdatePushStatusRequest requestToPartner = new UpdatePushStatusRequest();
			requestToPartner.setBusiId(busiId);
			requestToPartner.setPushStatus(PushStatus.YI_TUI_SONG.getCode());
			boolean flag = diepuService.pushStatus(requestToPartner);
			if(flag) {
				TransferYwInterviewInfo transferYwInterviewInfoUpdate = new TransferYwInterviewInfo();
				transferYwInterviewInfoUpdate.setId(id);
				transferYwInterviewInfoUpdate.setPushStatus(PushStatus.YI_TUI_SONG.getCode());
				transferYwInterviewInfoUpdate.initUpdateData(TransferModeID.GENG_XIN_MIAN_QIAN_FU_JIAN_TUI_SONG_ZHUANG_TAI.getCode(), TransferModeID.GENG_XIN_MIAN_QIAN_FU_JIAN_TUI_SONG_ZHUANG_TAI.getValue());
				transferYwInterviewInfoService.saveUpdateAndDelete(transferYwInterviewInfoUpdate, OperateType.edit);
				return true;
			}
		} catch (BasePartnerException e) {
			logger.error("HzicbcProxyServiceImpl.saveSynPushStatus partner exception ", e);
		} catch(Exception e) {
			logger.error("HzicbcProxyServiceImpl.saveSynPushStatus system exception ", e);
		}
		
		//推送失败=================================
		//下载面签附件
		newTransaction.savePushStatus(ordeRno, busiId);
		return false;
	}
	
	@Override
	public boolean downloadInterviewMedia(String ordeRno, String busiId) {
		if(!StringUtils.isNoneBlank(ordeRno, busiId)) {
			logger.error("下载面签视频，参数为空，ordeRno：{}， busiId :{}.", ordeRno, busiId);
			return true;
		}
		try {
			
			TransferYwInterviewInfo transferYwInterviewInfo = new TransferYwInterviewInfo();
			transferYwInterviewInfo.setDpStatus(DpStatus.NORMAL.getCode());
			transferYwInterviewInfo.setBusiId(busiId);
			transferYwInterviewInfo = transferYwInterviewInfoService.selectRefined(transferYwInterviewInfo);
			if(null == transferYwInterviewInfo) {
				logger.error("HzicbcProxyServiceImpl.downloadInterviewMedia. 面签信息记录为空，busiId ： {}.", busiId);
				throw new BasePartnerException(PartnerErrorCode.RECORD_INTERVIEW_MISSING.getCode(), PartnerErrorCode.RECORD_INTERVIEW_MISSING.getName());
			}
			String id = transferYwInterviewInfo.getId();
			
			//目录
			String dataFormat = DateUtil.dateTo8Str(new Date());
			String filePath = fileProxyConfig.getMianqianRonglianYun() + dataFormat + "/";  //数据库地址
			File folder = new File(fileProxyConfig.getBasePathNginx() + filePath);//保存地址
			if(!folder.exists()) {
				folder.mkdirs();
			}
			
			String urlQiniu = transferYwInterviewInfo.getUrlQiniu(); //数据库远程路径
			String fileName = urlQiniu.substring(urlQiniu.lastIndexOf("/") + 1);
			String urlLocal = filePath + fileName;
			try {
				File localFile = new File(fileProxyConfig.getBasePathNginx() + urlLocal);
				FileUtils.copyURLToFile(new URL(urlQiniu), localFile);
			} catch (IOException e) {
				logger.error("拷贝远程路径文件到本地失败。业务ID：{}，路径：{}。",busiId, urlQiniu, e);
				throw e;
			}
			
			UpdateDownloadStatusRequest updateDownloadStatusRequest = new UpdateDownloadStatusRequest();
			updateDownloadStatusRequest.setBusiId(busiId);
			updateDownloadStatusRequest.setDownloadStatus(DownloadStatus.YI_XIA_ZAI.getCode());
			updateDownloadStatusRequest.setUrlLocal(urlLocal);
			boolean pushDownloadStatus = diepuService.downloadStatus(updateDownloadStatusRequest);
			
			TransferYwInterviewInfo transferYwInterviewInfoUpdate = new TransferYwInterviewInfo();
			transferYwInterviewInfoUpdate.setId(id);
			if(pushDownloadStatus) {
				transferYwInterviewInfoUpdate.setDownloadStatus(DownloadStatus.YI_XIA_ZAI.getCode()); //推送成功后才更新已下载
			} else {
				transferYwInterviewInfoUpdate.setDownloadStatus(DownloadStatus.WEI_XIA_ZAI.getCode());
			}
			transferYwInterviewInfoUpdate.initUpdateData(SystemConsts.DEFAULT_ID, TransferModeID.TUI_SONG_MIAN_QIAN_SHI_PIN.getValue());
			transferYwInterviewInfoUpdate.setUrlLocal(urlLocal);
			Integer pushStatus = transferYwInterviewInfoUpdate.getPushStatus();
			if(PushStatus.YI_TUI_SONG.getCode().equals(pushStatus)) {
				transferYwInterviewInfoUpdate.setPushStatus(PushStatus.WEI_TUI_SONG.getCode());
			}
			
			transferYwInterviewInfoService.saveUpdateAndDelete(transferYwInterviewInfoUpdate, OperateType.edit);
			return true;
		} catch (BasePartnerException e) {
			logger.error("HzicbcProxyServiceImpl.downloadInterviewMedia partner exception ", e);
		} catch(Exception | IOException e) {
			logger.error("HzicbcProxyServiceImpl.downloadInterviewMedia system exception ", e);
		}
		return false;
	}
	
	/**
	 * 通用业务多媒体资料补充接口
	 * @param busiId
	 * @return
	 */
	public boolean multiMediaUpload(String ordeRno, String busiId) {
		if(!StringUtils.isNoneBlank(ordeRno, busiId)) {
			logger.error("通用业务多媒体资料补充接口，参数为空，ordeRno：{}， busiId :{}.", ordeRno, busiId);
			return true;
		}
		
		try {
			TransferYwInterviewInfo transferYwInterviewInfo = new TransferYwInterviewInfo();
			transferYwInterviewInfo.setDpStatus(DpStatus.NORMAL.getCode());
			transferYwInterviewInfo.setBusiId(busiId);
			transferYwInterviewInfo = transferYwInterviewInfoService.selectRefined(transferYwInterviewInfo);
			if(null == transferYwInterviewInfo) {
				logger.error("HzicbcProxyServiceImpl.multiMediaUpload. 面签信息记录为空，busiId ： {}.", busiId);
				throw new BasePartnerException(PartnerErrorCode.RECORD_INTERVIEW_MISSING.getCode(), PartnerErrorCode.RECORD_INTERVIEW_MISSING.getName());
			}
			String id = transferYwInterviewInfo.getId();
			
			MultimediauploadRequest request = new MultimediauploadRequest();
			PublicRequest pub = preparedInterviewPub(ordeRno);
			request.setPub(pub);
			
			MultimediauploadInfo req = new MultimediauploadInfo();
			List<PicInfo> pics = new ArrayList<PicInfo>();
			PicInfo picInfo = new PicInfo();
			picInfo.setPicid(PicIdType.INTERVIEW_MIANQIAN_BAOGAO_ZIP.getCode());
			String urlLocal = transferYwInterviewInfo.getUrlLocal();
			if(StringUtils.isBlank(urlLocal)) {
				logger.error("HzicbcProxyServiceImpl.multiMediaUpload.面签记录中urlLocal为空，busiId ： {}.", busiId);
				throw new BasePartnerException(PartnerErrorCode.INTERVIEW_MEDIA_UNSYNC.getCode(), PartnerErrorCode.INTERVIEW_MEDIA_UNSYNC.getName());
			}
			picInfo.setPicurl(fileProxyConfig.getGateWayNginx() + urlLocal + "?imageName=" +urlLocal.substring(urlLocal.lastIndexOf("/") + 1));
			picInfo.setPicnote(PicIdType.INTERVIEW_MIANQIAN_BAOGAO_ZIP.getName());
			pics.add(picInfo);
			req.setPics(pics);
			request.setReq(req);
			boolean result = hzicbcService.multiMediaUpload(request, hzicbcConfig.getPlatno());
			if(result) {
				UpdatePushStatusRequest requestToPartner = new UpdatePushStatusRequest();
				requestToPartner.setBusiId(busiId);
				requestToPartner.setPushStatus(PushStatus.YI_TUI_SONG.getCode());
				boolean flag = diepuService.pushStatus(requestToPartner);
				if(flag) {
					TransferYwInterviewInfo transferYwInterviewInfoUpdate = new TransferYwInterviewInfo();
					transferYwInterviewInfoUpdate.setId(id);
					transferYwInterviewInfoUpdate.setPushStatus(PushStatus.YI_TUI_SONG.getCode());
					transferYwInterviewInfoUpdate.initUpdateData(TransferModeID.TUI_SONG_MIAN_QIAN_SHI_PIN.getCode(), TransferModeID.M_TRANSFER_XZMQFJ.getValue());
					transferYwInterviewInfoService.saveUpdateAndDelete(transferYwInterviewInfoUpdate, OperateType.edit);
					return true;
				} else {
					logger.error("HzicbcProxyServiceImpl.multiMediaUpload. 更新主程序推送状态失败.");
					newTransaction.savePushStatus(ordeRno, busiId);
					return false;//不需要再写任务，直接结束
				}
			} else {
				logger.error("HzicbcProxyServiceImpl.multiMediaUpload. 推送面签视频到工商银行失败.");
				//推送面签附件
				newTransaction.saveSendMultiMediaUpload(ordeRno, busiId);
				return false;//需要写重新推送的任务，然后结束
			}
		} catch (BasePartnerException e) {
			logger.error("HzicbcProxyServiceImpl.multiMediaUpload partner exception ", e);
		} catch(Exception e) {
			logger.error("HzicbcProxyServiceImpl.multiMediaUpload system exception ", e);
		}
		
		//推送失败=================================
		//下载面签附件
		newTransaction.saveDownloadInterviewMedia(ordeRno, busiId);
		//推送面签附件
		newTransaction.saveSendMultiMediaUpload(ordeRno, busiId);
		return false;
	}
	
	@Override
	public HzicbcBaseResponse saveMultimediaBack(String orderno, String backnote) {
		HzicbcBaseResponse response = new HzicbcBaseResponse();
		TransferYwOrdernoBank transferYwOrdernoBank = transferYwOrdernoBankService.getByOrderNo(orderno);
		String busiId = Optional.ofNullable(transferYwOrdernoBank).map(item -> item.getBusiId()).orElse(null);
		if(StringUtils.isBlank(busiId)) {
			logger.error("HzicbcProxyServiceImpl.saveMultimediaBack error. transferYwOrdernoBank is null or busiId is blank, orderno : {}.", orderno);
			response.setPub(PublicResponse.failBusi());
			return response;
		}
		
		try {
			UpdatePushStatusRequest request = new UpdatePushStatusRequest();
			request.setBusiId(busiId);
			request.setPushStatus(PushStatus.TUI_HUI.getCode());
			request.setBacknote(backnote);
			boolean flag = diepuService.pushStatus(request);
			if(!flag) {
				logger.error("HzicbcProxyServiceImpl.saveMultimediaBack push status to main error, orderno : {}.", orderno);
				response.setPub(PublicResponse.failBusi());
				return response;
			}
			TransferYwInterviewInfo transferYwInterviewInfo = new TransferYwInterviewInfo();
			transferYwInterviewInfo.setBusiId(busiId);
			transferYwInterviewInfo.setDpStatus(DpStatus.NORMAL.getCode());
			transferYwInterviewInfo = transferYwInterviewInfoService.selectRefined(transferYwInterviewInfo);
			if(null == transferYwInterviewInfo) {
				logger.error("HzicbcProxyServiceImpl.saveMultimediaBack, transferYwInterviewInfo is nulll. orderno : {}, busiId : {}.", orderno, busiId);
				response.setPub(PublicResponse.failBusi());
				return response;
			}
			TransferYwInterviewInfo transferYwInterviewInfoUpdate = new TransferYwInterviewInfo();
			transferYwInterviewInfoUpdate.setId(transferYwInterviewInfo.getId());
			transferYwInterviewInfoUpdate.setPushStatus(PushStatus.TUI_HUI.getCode());
			transferYwInterviewInfoUpdate.setRemarks(backnote);
			transferYwInterviewInfoUpdate.initUpdateData(TransferModeID.MIAN_QIAN_SHI_PIN_TUI_HUI.getCode(), TransferModeID.MIAN_QIAN_SHI_PIN_TUI_HUI.getValue());
			transferYwInterviewInfoService.saveUpdateAndDelete(transferYwInterviewInfoUpdate, OperateType.edit);
			response.setPub(PublicResponse.success());
			return response;
		} catch (BasePartnerException e) {
			logger.error("HzicbcProxyServiceImpl.saveMultimediaBack happend exception. orderno is {}. errorCode is {}, errorMsg is {}.", orderno, e.getErrorCode(), e.getErrorMsg(), e);
			response.setPub(PublicResponse.failBusi());
			return response;
		}
	}
	
	@Override
	public HandPicResponse handPic(String orderno, PicIdType picIdType) {
		HandPicResponse response = new HandPicResponse();
		
		TransferOtherAttachmentsExt transferOtherAttachmentsExt = new TransferOtherAttachmentsExt();
		transferOtherAttachmentsExt.withOutPage();
		transferOtherAttachmentsExt.setBaseWhere();
		transferOtherAttachmentsExt.setBankOrderNo(orderno);
		
		List<String> includeFileLabels = new ArrayList<String>();
		switch (picIdType) {
		case SGHQ_XYKQCZXFQFKYWSQB: //【手工获取】信用卡汽车专项分期付款业务申请表
			includeFileLabels.add(AttachmentLabel.FEN_QI_XIN_YONG_KA_QI_CHE_ZHUAN_XIANG_FEN_QI_FU_KUAN.getCode());
			break;
		case SGHQ_HT_MDXYKTJFQFK_DYHD: //【手工获取】合同：牡丹信用卡透支分期付款/抵押合同（即三合一新合同）
			includeFileLabels.add(AttachmentLabel.FEN_QI_DI_YA_FEN_QI_HE_TONG_FENG_MIAN.getCode());
			includeFileLabels.add(AttachmentLabel.FEN_QI_DI_YA_FEN_QI_HE_TONG_1.getCode());
			includeFileLabels.add(AttachmentLabel.FEN_QI_DI_YA_FEN_QI_HE_TONG_2.getCode());
			includeFileLabels.add(AttachmentLabel.FEN_QI_DI_YA_FEN_QI_HE_TONG_3.getCode());
			includeFileLabels.add(AttachmentLabel.FEN_QI_DI_YA_FEN_QI_HE_TONG_4.getCode());
			includeFileLabels.add(AttachmentLabel.FEN_QI_DI_YA_FEN_QI_HE_TONG_5.getCode());
			includeFileLabels.add(AttachmentLabel.FEN_QI_DI_YA_FEN_QI_HE_TONG_6.getCode());
			break;
		case SGHQ_QCXSHT: //【手工获取】汽车销售合同
			includeFileLabels.add(AttachmentLabel.FEN_QI_WEI_TUO_GOU_CHE_HE_TONG.getCode());
			break;
		case SGHQ_GTHKRCRH: //【手工获取】共同还款人承诺函
			includeFileLabels.add(AttachmentLabel.FEN_QI_GONG_TONG_HUAN_KUAN_REN_CHENG_RUO_HAN.getCode());
			break;
		case SGHQ_DBGSDBCRH://【手工获取】担保公司担保承诺函
			includeFileLabels.add(AttachmentLabel.FEN_QI_DAN_BAO_CHENG_RUO_HAN.getCode());
			break;
		case SGHQ_SFZ://【手工获取】身份证
			includeFileLabels.add(AttachmentLabel.SHEN_FEN_ZHENG_MING_ZHENG_MIAN.getCode());
			includeFileLabels.add(AttachmentLabel.SHEN_FEN_ZHENG_MING_FAN_MIAN.getCode());
			includeFileLabels.add(AttachmentLabel.PO_SHEN_FEN_ZHENG_MING_ZHENG_MIAN.getCode());
			includeFileLabels.add(AttachmentLabel.PO_SHEN_FEN_ZHENG_MING_FAN_MIAN.getCode());
			break;
		case SGHQ_HKB://【手工获取】户口本
			includeFileLabels.add(AttachmentLabel.FEN_QI_HU_KOU_BEN1.getCode());
			includeFileLabels.add(AttachmentLabel.FEN_QI_HU_KOU_BEN2.getCode());
			includeFileLabels.add(AttachmentLabel.FEN_QI_HU_KOU_BEN3.getCode());
			includeFileLabels.add(AttachmentLabel.FEN_QI_HU_KOU_BEN4.getCode());
			break;
		case SGHQ_SRZM://【手工获取】收入申明
			includeFileLabels.add(AttachmentLabel.FEN_QI_SHOU_RU_ZHENG_MING1.getCode());
			includeFileLabels.add(AttachmentLabel.FEN_QI_SHOU_RU_ZHENG_MING2.getCode());
			break;
		case SGHQ_HYZM://【手工获取】婚姻证明
			includeFileLabels.add(AttachmentLabel.FEN_QI_DAN_SHEN_JU_JIE_SHU.getCode());
			includeFileLabels.add(AttachmentLabel.FEN_QI_LI_HUN_ZHENG.getCode());
			includeFileLabels.add(AttachmentLabel.FEN_QI_JIE_HUN_JU_JIE_SHU.getCode());
			includeFileLabels.add(AttachmentLabel.FEN_QI_JIE_HUN_ZHENG.getCode());
			
			includeFileLabels.add(AttachmentLabel.JIE_HUN_ZHENG.getCode());
			includeFileLabels.add(AttachmentLabel.DAN_SHEN_JU_JIE_SHU.getCode());
			break;
		case SGHQ_ZCZM://【手工获取】资产证明
			includeFileLabels.add(AttachmentLabel.FEN_QI_ZHI_CHAN_ZHENG_MING.getCode());
			
			break;
		case SGHQ_SFKPZ://【手工获取】首付款凭证
			includeFileLabels.add(AttachmentLabel.FEN_QI_SHOU_FU_KUAN_PIN_ZHENG.getCode());
			break;
		case SGHQ_GCFP://【手工获取】购车发票
			includeFileLabels.add(AttachmentLabel.FEN_QI_GOU_CHE_FA_PIAO.getCode());
			break;
		case SGHQ_YHKQGD://【手工获取】银行卡签购单
			includeFileLabels.add(AttachmentLabel.FEN_QI_YIN_HANG_KA_QIAN_GOU_DAN.getCode());
			break;
		case SGHQ_CLHGZ://【手工获取】车辆合格证
			includeFileLabels.add(AttachmentLabel.FEN_QI_CHE_LIAN_HE_GE_ZHENG.getCode());
			
			break;
		case SGHQ_ESCPGBG://【手工获取】二手车评估报告
			includeFileLabels.add(AttachmentLabel.FEN_QI_ER_SHOU_CHE_PING_GU_BAOGAO.getCode());
			break;
		case SGHQ_JDCLBXD://【手工获取】机动车辆保险单
			includeFileLabels.add(AttachmentLabel.FEN_QI_JIAO_QIANG_XIAN_BAODAN.getCode());
			includeFileLabels.add(AttachmentLabel.FEN_QI_SHANG_YAN_XIAN_BAODAN.getCode());
			
//			includeFileLabels.add(AttachmentLabel.TI_CHE_QI_CHE_BAO_DAN.getCode());
//			includeFileLabels.add(AttachmentLabel.GUO_HU_BAO_DAN.getCode());
//			
//			includeFileLabels.add(AttachmentLabel.XIN_CHE_JIAO_QIANG_XIAN_BAO_DAN.getCode());
//			includeFileLabels.add(AttachmentLabel.XIN_CHE_JIAO_SHANG_YE_XIAN_BAO_DAN.getCode());
//			includeFileLabels.add(AttachmentLabel.ER_SHOU_CHE_JIAO_QIANG_XIAN_BAO_DAN.getCode());
//			includeFileLabels.add(AttachmentLabel.ER_SHOU_CHE_JIAO_SHANG_YE_XIAN_BAO_DAN.getCode());
			break;
		case SGHQ_JFJMQZPLZ://【手工获取】家访及面签照片两张
//			transferOtherAttachmentsExt.setRows(2);
			includeFileLabels.add(AttachmentLabel.FEN_QI_JIA_FANG_MIAN_QIAN_ZHAOPIAN1.getCode());
			includeFileLabels.add(AttachmentLabel.FEN_QI_JIA_FANG_MIAN_QIAN_ZHAOPIAN2.getCode());
			break;
		case SGHQ_TCSXGYXZLLZ://【手工获取】提车时相关影像资料两张
			transferOtherAttachmentsExt.setRows(2);
			includeFileLabels.add(AttachmentLabel.FEN_QI_TI_CHE_YING_XIANG_ZILIAO1.getCode());
			includeFileLabels.add(AttachmentLabel.FEN_QI_TI_CHE_YING_XIANG_ZILIAO2.getCode());
			break;
		case SGHQ_KHSQSQZZP://【手工获取】客户授权书签字照片
			includeFileLabels.add(AttachmentLabel.FEN_QI_KEHU_SHOUQIAN_SHU_QIANZI_ZHAOPIAN.getCode());
			
			break;
		case SGHQ_JDCDJZS_QZ_FYJ://【手工获取】机动车登记证书（权证）复印件
			includeFileLabels.add(AttachmentLabel.FEN_QI_JI_DONG_CHE_DENGJI_ZHENG.getCode());
			
			break;
		case SGHQ_DLWTSQS://【手工获取】代领委托授权书（三合一）
			includeFileLabels.add(AttachmentLabel.FEN_QI_DAI_LING_WEI_TUO_SHOU_QUAN_SHU_3_HE_YI.getCode());
			
			break;
		case SGHQ_GCFQFKSXFWTDKSQS: //【手工获取】购车分期付款手续费委托代扣授权书
			break;
		default:
			logger.error("HzicbcProxyServiceImpl.handPic param picid is error.");
			response.setPub(PublicResponse.failParam());
			return response;
		}
		if(CollectionUtils.isEmpty(includeFileLabels)) {
			logger.error("HzicbcProxyServiceImpl.handPic param picid is error.");
			response.setPub(PublicResponse.failParam());
			return response;
		}
		transferOtherAttachmentsExt.setIncludeFileLabels(includeFileLabels);
		List<TransferOtherAttachments> transferOtherAttachments = transferOtherAttachmentsMapper.selectByExt(transferOtherAttachmentsExt);
		List<PicInfo> pics = getPicInfos(transferOtherAttachments);
		
		HandPicDetail handPicDetail = new HandPicDetail();
		handPicDetail.setPics(pics);
		handPicDetail.setPicnum(pics.size());
		response.setAns(handPicDetail);
		response.setPub(PublicResponse.success());
		return response;
	}
	
	@Override
	public HzicbcBaseResponse saveApplyDiviBack(String orderno, String backnote, boolean hzicbc) {
		HzicbcBaseResponse response = new HzicbcBaseResponse();
		
		TransferDzApplyDivi transferDzApplyDivi = new TransferDzApplyDivi();
		transferDzApplyDivi.setDpStatus(DpStatus.NORMAL.getCode());
		transferDzApplyDivi.setBankOrderNo(orderno);  //同一单不会变，且不会删除
		transferDzApplyDivi.setOrderSql("`CREATED` DESC");
		transferDzApplyDivi = transferDzApplyDiviMapper.selectRefined(transferDzApplyDivi);
		if(null == transferDzApplyDivi) {
			logger.warn("HzicbcController.applyDiviBack transferDzApplyDivi record is missing.");
			response.setPub(PublicResponse.success()); //订单异常，当成退回成功
			return response;
		}
		
		transferDzApplyDivi.setApplyDiviFlag(hzicbc ? "1" : null); //杭州工行退回则改成1，否则不修改
		transferDzApplyDiviService.updateJust(transferDzApplyDivi);
		
		try {
			String busiId = transferDzApplyDivi.getBusiId();
			
			ApplyDiviBackProxyRequest request = new ApplyDiviBackProxyRequest();
			request.setBacknote(backnote);
			request.setBusiId(busiId);
			
			boolean applyBack = diepuService.applyDiviBack(request);
			if(applyBack) { //通知成功
				response.setPub(PublicResponse.success());
				
				transferDzApplyDivi.initUpdateData(SystemConsts.DEFAULT_ID, "申请分期退回接口");
				transferDzApplyDivi.setApplyDiviStatus(ApplyDiviStatus.TUI_HUI.getCode());
				transferDzApplyDivi.setBankApplyDiviStatus(String.valueOf(HzicbcApplyDiviStatus.SHEN_PI_WEI_TONG_GUO.getCode()));
				transferDzApplyDivi.setReasonBack(backnote);
				transferDzApplyDiviMapper.updateByPrimaryKeySelective(transferDzApplyDivi);
				
				response.setPub(PublicResponse.success());
			} else {
				logger.error("HzicbcController.applyDiviBack busi error, busiId is {}.", busiId);
				response.setPub(PublicResponse.failBusi());
			}
		} catch (BasePartnerException e) {
			logger.error("HzicbcController.applyDiviBack happend customer exception. errorCode is {}, errorMsg is {}.", e.getErrorCode(), e.getErrorMsg(), e);
			response.setPub(PublicResponse.failParam());
		} catch (Exception e) {
			logger.error("HzicbcController.applyDiviBack happend exception. exception stack is : ", e);
			response.setPub(PublicResponse.failError());
		}
		return response;
	}
	
	@Override
	public String saveFileDownload(FileListType fileListType, String filesrc, String datadt) {
//	       写入到【中转_日志表】：transfer_mode_id（M_tranfer_xzwjqd）、describe_event（下载开卡清单、下载逾期催收清单等）、status_event（成功、失败）
		TransferLogs transferLogs = new TransferLogs();
		transferLogs.initInsertData(SystemConsts.DEFAULT_ID, "文件清单信息下载");
		transferLogs.setTransferModeId(TransferModeID.XZWJQD.getCode());
		transferLogs.setTransferModeName(TransferModeID.XZWJQD.getValue());
		transferLogs.setDescribeEvent(parseDescribe(fileListType));
		try {
			FileDownloadRequest request = new FileDownloadRequest();
			PublicRequest pub = preparedPub(null, null);
			request.setPub(pub);
			transferLogs.setCmpSeq(pub.getCmpseq());
			transferLogs.setBusiType("zy");
			
			FileDownloadInfo fileInfo = new FileDownloadInfo();
			fileInfo.setFiletype(fileListType.getCode());
			fileInfo.setFilesrc(filesrc);
			fileInfo.setDatadt(datadt);
			request.setReq(fileInfo);
			
			String localPath = parsePath(fileListType);
			if(StringUtils.isBlank(localPath)) {
				transferLogs.setStatusEvent(StatusEventLog.FAIL.getCode());
				logger.error("HzicbcProxyServiceImpl.saveFileDownload params is error, parsePath from fileListType[{}] fail.", fileListType.getCode());
				return null;
			}
			File folder = new File(localPath);
			if(!folder.exists()) {
				folder.mkdirs();
			}
			localPath = localPath + filesrc;
			boolean fileDownload = hzicbcService.fileDownload(request, filesrc, localPath, hzicbcConfig.getPlatno());
			if(!fileDownload) {
				transferLogs.setStatusEvent(StatusEventLog.FAIL.getCode());
				logger.error("HzicbcProxyServiceImpl.saveFileDownload save file to local fail.", fileListType.getCode());
				return null;
			}
			transferLogs.setStatusEvent(StatusEventLog.SUCCESS.getCode());
			return localPath;
		} catch (Exception e) {
			transferLogs.setStatusEvent(StatusEventLog.FAIL.getCode());
			logger.error("HzicbcProxyServiceImpl.saveFileDownload happend exception. fileListType is {}, filesrc is {}, datadt is {}. exception is {}.", fileListType.getName(), filesrc, datadt, e);
			return null;
		} finally {
			transferLogsMapper.insert(transferLogs);
		}
	}
	
	@Override
	public boolean saveApplyDiviStatus(String orderno) {
		boolean result = true;
		String busiId = null;
		Date now = new Date();
		try {
			TransferYwOrdernoBank transferYwOrdernoBank = transferYwOrdernoBankService.getByOrderNo(orderno);
			if(null == transferYwOrdernoBank || StringUtils.isBlank(transferYwOrdernoBank.getBusiId())) {
				logger.error("HzicbcProxyServiceImpl.saveApplyDiviStatus params is error, transferYwOrdernoBank record missing. params : orderno is {}.", orderno);
				throw new BasePartnerException(PartnerErrorCode.RECORD_ORDER_MISSING.getCode(), PartnerErrorCode.RECORD_ORDER_MISSING.getName());
			}
			busiId = transferYwOrdernoBank.getBusiId();
			String zoneno = transferYwOrdernoBank.getAreaId();
			
			ApplyStatusRequest request = new ApplyStatusRequest();
			PublicRequest pub = preparedPub(orderno, zoneno);
			request.setPub(pub);
			ApplyStatusInfo applyStatusInfo = hzicbcService.applyDiviStatus(request, hzicbcConfig.getPlatno());
			
			TransferDzApplyDivi transferDzApplyDivi = new TransferDzApplyDivi();
			transferDzApplyDivi.setBankOrderNo(orderno);
			transferDzApplyDivi.setDpStatus(DpStatus.NORMAL.getCode());
			transferDzApplyDivi.setOrderSql("`CREATED` DESC");
			transferDzApplyDivi = transferDzApplyDiviMapper.selectRefined(transferDzApplyDivi);
			if(null == transferDzApplyDivi) {
				logger.error("HzicbcProxyServiceImpl.saveApplyDiviStatus params is error, transferDzApplyDivi record missing. params : orderno is {}, zoneno is {}.", orderno, zoneno);
				throw new BasePartnerException(PartnerErrorCode.RECORD_DIVI_MISSING.getCode(), PartnerErrorCode.RECORD_DIVI_MISSING.getName());
			}
			String bankApplyDiviStatus = transferDzApplyDivi.getBankApplyDiviStatus();
			Integer status = applyStatusInfo.getStatus();
			if(HzicbcApplyDiviStatus.DAI_SHOU_LI.getCode().equals(status) 
					|| HzicbcApplyDiviStatus.SHEN_PI_ZHONG.getCode().equals(status)
					|| HzicbcApplyDiviStatus.SHEN_PI_TONG_GUO.getCode().equals(status)) {
				
			}
			if(StringUtils.isBlank(bankApplyDiviStatus) || Integer.parseInt(bankApplyDiviStatus) != status) {
				ApplyDiviStatusProxyRequest applyDiviStatusProxyRequest = new ApplyDiviStatusProxyRequest();
				BeanUtils.copyProperties(applyStatusInfo, applyDiviStatusProxyRequest);
				//基本字段赋值
				applyDiviStatusProxyRequest.setDiviId(transferDzApplyDivi.getId());
				applyDiviStatusProxyRequest.setBusiId(busiId);
				
				boolean applyDiviStatus = diepuService.applyDiviStatus(applyDiviStatusProxyRequest);
				if(applyDiviStatus) { //通知成功，这时才更新，否则不更新，以防主程序和proxy不同步的情况
					BeanUtils.copyProperties(applyStatusInfo, transferDzApplyDivi);
					transferDzApplyDivi.initUpdateData(SystemConsts.DEFAULT_ID, "查询申请进度");
					try {
						String amount = applyStatusInfo.getAmount();
						transferDzApplyDivi.setAmount(StringUtils.isBlank(amount) ? 0d : Double.valueOf(amount));
						String term = applyStatusInfo.getTerm();
						transferDzApplyDivi.setTerm(StringUtils.isBlank(term) ? 0 : Integer.valueOf(amount));
					} catch (NumberFormatException e) {
						logger.error("HzicbcProxyServiceImpl.saveApplyDiviStatus parse term {} or amount {} error. params is {}.", applyStatusInfo.getTerm(), applyStatusInfo.getAmount(), JSON.toJSONString(applyStatusInfo));
					}
					try {
						String loandate = applyStatusInfo.getLoandate();
						Date loandate_ = StringUtils.isBlank(loandate) ? now : sdf.parse(loandate);
						transferDzApplyDivi.setLoandate(loandate_);
					} catch (ParseException e) {
						logger.error("HzicbcProxyServiceImpl.saveApplyDiviStatus parse loandate {} error. params is {}.", JSON.toJSONString(request));
					}
					transferDzApplyDivi.setBankApplyDiviStatus(String.valueOf(status));
					if(HzicbcApplyDiviStatus.SHOU_LI_SHI_BAI.getCode().equals(status) || HzicbcApplyDiviStatus.SHEN_PI_WEI_TONG_GUO.getCode().equals(status)) {
						transferDzApplyDivi.setApplyDiviStatus(ApplyDiviStatus.SHEN_QING_SHI_BAI.getCode());
					} else if(HzicbcApplyDiviStatus.FANG_KUAN_CHENG_GONG.getCode().equals(status)){
						transferDzApplyDivi.setApplyDiviStatus(ApplyDiviStatus.SHEN_QING_CHENG_GONG.getCode());
					}
					transferDzApplyDiviMapper.updateByPrimaryKeySelective(transferDzApplyDivi);
				} else {
					logger.error("HzicbcProxyServiceImpl.saveApplyDiviStatus notice the main program fail, please repare it and try again!!!! params : orderno is {}, zoneno is {}.", orderno, zoneno);
				}
				result = applyDiviStatus;
			}
			
			if(HzicbcApplyDiviStatus.DAI_SHOU_LI.equals(status) || HzicbcApplyDiviStatus.SHEN_PI_ZHONG.equals(status) || HzicbcApplyDiviStatus.SHEN_PI_TONG_GUO.equals(status)) {//状态没有定位再次尝试
				result = false;
			}
			
		} catch(BasePartnerException e) {
			result = false;
			logger.error("HzicbcProxyServiceImpl.saveApplyDiviStatus happend customer exception. orderno is {}. errorCode is {}, errorMsg is {}.", orderno, e.getErrorCode(), e.getErrorMsg(), e);
		} catch (Exception e) {
			result = false;
			logger.error("HzicbcProxyServiceImpl.saveApplyDiviStatus happend exception. orderno is {}. exception is {}.", orderno, e);
		} finally {
			if(!result) { //失败或者状态不确定，需要再次尝试
				newTransaction.saveAfterApplyDiviStatusHzicbc(orderno, busiId);
			}
		}
		return result;
	}
	
	@Override
	public boolean saveApplyDivi(String orderno) {
		String busiId = null;
		try {
			if(StringUtils.isBlank(orderno)) {
				throw new BasePartnerException(PartnerErrorCode.ORDER_NO_EMPTY.getCode(), PartnerErrorCode.ORDER_NO_EMPTY.getName());
			}
//			TransferYwOrdernoBank transferYwOrdernoBank = new TransferYwOrdernoBank();
//			transferYwOrdernoBank.setOrdeRno(orderno);
//			transferYwOrdernoBank.setDpStatus(DpStatus.NORMAL.getCode());
//			transferYwOrdernoBank.setOrderSql("`CREATED` DESC");
//			transferYwOrdernoBank = transferYwOrdernoBankMapper.selectRefined(transferYwOrdernoBank);
			TransferYwOrdernoBank transferYwOrdernoBank = transferYwOrdernoBankService.getByOrderNo(orderno);
			if(null == transferYwOrdernoBank || StringUtils.isBlank(transferYwOrdernoBank.getBusiId())) {
				throw new BasePartnerException(PartnerErrorCode.BUSI_ID_MISSING.getCode(), PartnerErrorCode.BUSI_ID_MISSING.getName());
			}
			String zoneno = transferYwOrdernoBank.getAreaId();
			busiId = transferYwOrdernoBank.getBusiId();
			if(StringUtils.isBlank(zoneno)) {
				throw new BasePartnerException(PartnerErrorCode.ZONENO_MISSING.getCode(), PartnerErrorCode.ZONENO_MISSING.getName());
			}
			if(StringUtils.isBlank(busiId)) {
				throw new BasePartnerException(PartnerErrorCode.BUSI_ID_MISSING.getCode(), PartnerErrorCode.BUSI_ID_MISSING.getName());
			}
			TransferYwBusinessCar transferYwBusinessCar = new TransferYwBusinessCar();
			transferYwBusinessCar.setBusiId(busiId);
			transferYwBusinessCar.setDpStatus(DpStatus.NORMAL.getCode());
			transferYwBusinessCar = transferYwBusinessCarMapper.selectRefined(transferYwBusinessCar);
			if(null == transferYwBusinessCar) {
				throw new BasePartnerException(PartnerErrorCode.RECORD_CAR_MISSING.getCode(), PartnerErrorCode.RECORD_CAR_MISSING.getName());
			}
			String carType = transferYwBusinessCar.getCarType();
			boolean used = "02".equals(carType);
			
			/**
			 * 检查附件资料是否完整
			 */
			//@see PicIdType
			TransferOtherAttachmentsExt transferOtherAttachmentsExtParam = new TransferOtherAttachmentsExt();
			transferOtherAttachmentsExtParam.setBaseWhere();
			transferOtherAttachmentsExtParam.setBankOrderNo(orderno);
//			
			TransferOtherAttachments transferOtherAttachmentsParam = new TransferOtherAttachments();
			transferOtherAttachmentsParam.setDpStatus(DpStatus.NORMAL.getCode());
			transferOtherAttachmentsParam.setBankOrderNo(orderno);
//			if(used) {
//				transferOtherAttachmentsParam.setAttachmentSort(AttachmentSort.GUO_HU_QI_CHE_ZI_LIAO.getCode());
//				transferOtherAttachmentsParam.setFileLabel(AttachmentLabel.GUO_HU_DENG_JI_ZHENG_SHU1.getCode());
//			} else {
//				transferOtherAttachmentsParam.setAttachmentSort(AttachmentSort.TI_CHE_QI_CHE_ZI_LIAO.getCode());
//				transferOtherAttachmentsParam.setFileLabel(AttachmentLabel.TI_CHE_QI_CHE_DENGJIZHENG_1.getCode());
//			}
//			TransferOtherAttachments FQ_ZCDJ_1 = transferOtherAttachmentsMapper.selectRefined(transferOtherAttachmentsParam);
//			if(!checkCompleted(FQ_ZCDJ_1)){
//				throw new BasePartnerException(PartnerErrorCode.PIC_DIVI_MISSGING.getCode(), "【分期】注册登记证1缺失");
//			}
//			FQ_ZCDJ_1.setPicid(PicIdType.FQ_ZCDJ_1.getCode());
//			if(used) {
//				transferOtherAttachmentsParam.setAttachmentSort(AttachmentSort.GUO_HU_QI_CHE_ZI_LIAO.getCode());
//				transferOtherAttachmentsParam.setFileLabel(AttachmentLabel.GUO_HU_DENG_JI_ZHENG_SHU2.getCode());
//			} else {
//				transferOtherAttachmentsParam.setAttachmentSort(AttachmentSort.TI_CHE_QI_CHE_ZI_LIAO.getCode());
//				transferOtherAttachmentsParam.setFileLabel(AttachmentLabel.TI_CHE_QI_CHE_DENGJIZHENG_2.getCode());
//			}
//			TransferOtherAttachments FQ_ZCDJ_2 = transferOtherAttachmentsMapper.selectRefined(transferOtherAttachmentsParam);
//			if(!checkCompleted(FQ_ZCDJ_2)){
//				throw new BasePartnerException(PartnerErrorCode.PIC_DIVI_MISSGING.getCode(), "【分期】注册登记证2缺失");
//			}
//			FQ_ZCDJ_2.setPicid(PicIdType.FQ_ZCDJ_2.getCode());
			transferOtherAttachmentsParam.setAttachmentSort(AttachmentSort.SHEN_FEN_ZHENG_MING.getCode());
			transferOtherAttachmentsParam.setFileLabel(AttachmentLabel.SHEN_FEN_ZHENG_MING_ZHENG_MIAN.getCode());
			TransferOtherAttachments FQ_ZJ_BRZM = transferOtherAttachmentsMapper.selectRefined(transferOtherAttachmentsParam);
			if(!checkCompleted(FQ_ZJ_BRZM)){
				throw new BasePartnerException(PartnerErrorCode.PIC_DIVI_MISSGING.getCode(), "【分期】【证件】证件本人正面缺失");
			}
			FQ_ZJ_BRZM.setPicid(PicIdType.FQ_ZJ_BRZM.getCode());
			transferOtherAttachmentsParam.setAttachmentSort(AttachmentSort.SHEN_FEN_ZHENG_MING.getCode());
			transferOtherAttachmentsParam.setFileLabel(AttachmentLabel.SHEN_FEN_ZHENG_MING_FAN_MIAN.getCode());
			TransferOtherAttachments FQ_ZJ_BRFM = transferOtherAttachmentsMapper.selectRefined(transferOtherAttachmentsParam);
			if(!checkCompleted(FQ_ZJ_BRFM)){
				throw new BasePartnerException(PartnerErrorCode.PIC_DIVI_MISSGING.getCode(), "【分期】【证件】证件本人反面缺失");
			}
			FQ_ZJ_BRFM.setPicid(PicIdType.FQ_ZJ_BRFM.getCode());
			transferOtherAttachmentsParam.setAttachmentSort(AttachmentSort.PEI_OU_SHEN_FEN_ZHENG_MING.getCode());
			transferOtherAttachmentsParam.setFileLabel(AttachmentLabel.PO_SHEN_FEN_ZHENG_MING_ZHENG_MIAN.getCode());
			TransferOtherAttachments FQ_ZJ_POZM = transferOtherAttachmentsMapper.selectRefined(transferOtherAttachmentsParam);
			if(null != FQ_ZJ_POZM) {
				if(!checkCompleted(FQ_ZJ_POZM)){
					throw new BasePartnerException(PartnerErrorCode.PIC_DIVI_MISSGING.getCode(), "【分期】【证件】证件配偶正面缺失");
				}
				FQ_ZJ_POZM.setPicid(PicIdType.FQ_ZJ_POZM.getCode());
			}
			transferOtherAttachmentsParam.setAttachmentSort(AttachmentSort.PEI_OU_SHEN_FEN_ZHENG_MING.getCode());
			transferOtherAttachmentsParam.setFileLabel(AttachmentLabel.PO_SHEN_FEN_ZHENG_MING_FAN_MIAN.getCode());
			TransferOtherAttachments FQ_ZJ_POFM = transferOtherAttachmentsMapper.selectRefined(transferOtherAttachmentsParam);
			if(null != FQ_ZJ_POFM) {
				if(!checkCompleted(FQ_ZJ_POFM)){
					throw new BasePartnerException(PartnerErrorCode.PIC_DIVI_MISSGING.getCode(), "【分期】【证件】证件配偶反面缺失");
				}
				FQ_ZJ_POFM.setPicid(PicIdType.FQ_ZJ_POFM.getCode());
			}
//			transferOtherAttachmentsParam.setAttachmentSort(AttachmentSort.ZHONG_YAO_YUAN_JIAN.getCode());
//			transferOtherAttachmentsParam.setFileLabel(AttachmentLabel.JIE_HUN_ZHENG.getCode());
//			TransferOtherAttachments FQ_HYZM_JHZ = transferOtherAttachmentsMapper.selectRefined(transferOtherAttachmentsParam);
//			if(null != FQ_HYZM_JHZ) {
//				if(!checkCompleted(FQ_HYZM_JHZ)){
//					throw new BasePartnerException(PartnerErrorCode.PIC_DIVI_MISSGING.getCode(), "【分期】【婚姻证明】结婚证缺失");
//				}
//				FQ_HYZM_JHZ.setPicid(PicIdType.FQ_HYZM_JHZ.getCode());
//			}
//			transferOtherAttachmentsParam.setAttachmentSort(AttachmentSort.ZHONG_YAO_YUAN_JIAN.getCode());
//			transferOtherAttachmentsParam.setFileLabel(AttachmentLabel.DAN_SHEN_JU_JIE_SHU.getCode());
//			TransferOtherAttachments FQ_HYZM_DSZM = transferOtherAttachmentsMapper.selectRefined(transferOtherAttachmentsParam);
//			if(null != FQ_HYZM_DSZM) {
//				if(!checkCompleted(FQ_HYZM_DSZM)){
//					throw new BasePartnerException(PartnerErrorCode.PIC_DIVI_MISSGING.getCode(), "【分期】【婚姻证明】单身证明缺失");
//				}
//				FQ_HYZM_DSZM.setPicid(PicIdType.FQ_HYZM_DSZM.getCode());
//			}
//			if(used) {
//				transferOtherAttachmentsParam.setAttachmentSort(AttachmentSort.GUO_HU_QI_CHE_ZI_LIAO.getCode());
//				transferOtherAttachmentsParam.setFileLabel(AttachmentLabel.GUO_HU_ER_SHOU_CHE_FA_PIAO.getCode());
//			} else {
//				transferOtherAttachmentsParam.setAttachmentSort(AttachmentSort.TI_CHE_QI_CHE_ZI_LIAO.getCode());
//				transferOtherAttachmentsParam.setFileLabel(AttachmentLabel.TI_CHE_QI_CHE_FA_PIAO.getCode());
//			}
//			TransferOtherAttachments FQ_GCFP = transferOtherAttachmentsMapper.selectRefined(transferOtherAttachmentsParam);
//			if(!checkCompleted(FQ_GCFP)){
//				throw new BasePartnerException(PartnerErrorCode.PIC_DIVI_MISSGING.getCode(), "【分期】购车发票缺失");
//			}
//			FQ_GCFP.setPicid(PicIdType.FQ_GCFP.getCode());
//			transferOtherAttachmentsExtParam.setAttachmentSort(AttachmentSort.JIA_FANG.getCode());
//			transferOtherAttachmentsExtParam.setFileLabel(AttachmentLabel.JIA_FANG_SHANG_MEN_BAI_FANG.getCode());
//			transferOtherAttachmentsExtParam.setRows(3);
//			List<TransferOtherAttachments> FQ_SMZP_1s = transferOtherAttachmentsMapper.selectByExt(transferOtherAttachmentsExtParam);
//			if(CollectionUtils.isEmpty(FQ_SMZP_1s)) {
//				throw new BasePartnerException(PartnerErrorCode.PIC_DIVI_MISSGING.getCode(), "【分期】上门照片缺失");
//			}
//			int count = 0;
//			for(TransferOtherAttachments FQ_SMZP_1 : FQ_SMZP_1s) {
//				if(!checkCompleted(FQ_SMZP_1)){
//					throw new BasePartnerException(PartnerErrorCode.PIC_DIVI_MISSGING.getCode(), "【分期】上门照片缺失");
//				}
//				count++;
//				if(count == 1) {
//					FQ_SMZP_1.setPicid(PicIdType.FQ_SMZP_1.getCode());
//				} else if(count == 2) {
//					FQ_SMZP_1.setPicid(PicIdType.FQ_SMZP_2.getCode());
//				} else if(count == 3) {
//					FQ_SMZP_1.setPicid(PicIdType.FQ_SMZP_3.getCode());
//				}
//			}
//			transferOtherAttachmentsExtParam.setAttachmentSort(AttachmentSort.ZHU_JIE_REN_QIAN_ZI.getCode());
//			transferOtherAttachmentsExtParam.setFileLabel(AttachmentLabel.ZHU_JIE_REN_QIAN_ZI_ZHAO_PIAN.getCode());
//			transferOtherAttachmentsExtParam.setRows(2);
//			List<TransferOtherAttachments> FQ_KHQZ_1s = transferOtherAttachmentsMapper.selectByExt(transferOtherAttachmentsExtParam);
//			if(CollectionUtils.isEmpty(FQ_KHQZ_1s)) {
//				throw new BasePartnerException(PartnerErrorCode.PIC_DIVI_MISSGING.getCode(), "【分期】客户签字照片缺失");
//			}
//			count = 0;
//			for(TransferOtherAttachments FQ_KHQZ_1 : FQ_KHQZ_1s) {
//				if(!checkCompleted(FQ_KHQZ_1)){
//					throw new BasePartnerException(PartnerErrorCode.PIC_DIVI_MISSGING.getCode(), "【分期】客户签字照片缺失");
//				}
//				count++;
//				if(count == 1) {
//					FQ_KHQZ_1.setPicid(PicIdType.FQ_KHQZ_1.getCode());
//				} else if(count == 2) {
//					FQ_KHQZ_1.setPicid(PicIdType.FQ_KHQZ_2.getCode());
//				}
//			}
//			transferOtherAttachmentsParam.setAttachmentSort(AttachmentSort.ZHONG_YAO_YUAN_JIAN.getCode());
//			transferOtherAttachmentsParam.setFileLabel(AttachmentLabel.HU_KOU_BEN_SHOU_YE.getCode());
//			TransferOtherAttachments FQ_HK_HKB_1 = transferOtherAttachmentsMapper.selectRefined(transferOtherAttachmentsParam);
//			if(!checkCompleted(FQ_HK_HKB_1)){
//				throw new BasePartnerException(PartnerErrorCode.PIC_DIVI_MISSGING.getCode(), "【分期】【户口本】户口本1缺失");
//			}
//			FQ_HK_HKB_1.setPicid(PicIdType.FQ_HK_HKB_1.getCode());
//			transferOtherAttachmentsParam.setAttachmentSort(AttachmentSort.ZHONG_YAO_YUAN_JIAN.getCode());
//			transferOtherAttachmentsParam.setFileLabel(AttachmentLabel.HU_KOU_BEN_HU_ZHU_YE.getCode());
//			TransferOtherAttachments FQ_HK_HKB_2 = transferOtherAttachmentsMapper.selectRefined(transferOtherAttachmentsParam);
//			if(!checkCompleted(FQ_HK_HKB_2)){
//				throw new BasePartnerException(PartnerErrorCode.PIC_DIVI_MISSGING.getCode(), "【分期】【户口本】户口本2缺失");
//			}
//			FQ_HK_HKB_2.setPicid(PicIdType.FQ_HK_HKB_2.getCode());
//			transferOtherAttachmentsParam.setAttachmentSort(AttachmentSort.ZHONG_YAO_YUAN_JIAN.getCode());
//			transferOtherAttachmentsParam.setFileLabel(AttachmentLabel.HU_KOU_BEN_BEN_REN_YE.getCode());
//			TransferOtherAttachments FQ_HK_HKB_3 = transferOtherAttachmentsMapper.selectRefined(transferOtherAttachmentsParam);
//			if(!checkCompleted(FQ_HK_HKB_3)){
//				throw new BasePartnerException(PartnerErrorCode.PIC_DIVI_MISSGING.getCode(), "【分期】【户口本】户口本3缺失");
//			}
//			FQ_HK_HKB_3.setPicid(PicIdType.FQ_HK_HKB_3.getCode());
//			transferOtherAttachmentsParam.setAttachmentSort(AttachmentSort.ZHONG_YAO_YUAN_JIAN.getCode());
//			transferOtherAttachmentsParam.setFileLabel(AttachmentLabel.SHOU_RU_ZHENG_MING_ZHU_JIE_REN.getCode());
//			TransferOtherAttachments FQ_SRZM_1 = transferOtherAttachmentsMapper.selectRefined(transferOtherAttachmentsParam);
//			if(!checkCompleted(FQ_SRZM_1)){
//				throw new BasePartnerException(PartnerErrorCode.PIC_DIVI_MISSGING.getCode(), "【分期】【收入证明】收入证明1缺失");
//			}
//			FQ_SRZM_1.setPicid(PicIdType.FQ_SRZM_1.getCode());
//			transferOtherAttachmentsParam.setAttachmentSort(AttachmentSort.ZHONG_YAO_YUAN_JIAN.getCode());
//			transferOtherAttachmentsParam.setFileLabel(AttachmentLabel.SHOU_RU_ZHENG_MING_PEI_OU.getCode());
//			TransferOtherAttachments FQ_SRZM_2 = transferOtherAttachmentsMapper.selectRefined(transferOtherAttachmentsParam);
//			if(null != FQ_SRZM_2) {
//				if(!checkCompleted(FQ_SRZM_2)){
//					throw new BasePartnerException(PartnerErrorCode.PIC_DIVI_MISSGING.getCode(), "【分期】【收入证明】收入证明2缺失");
//				}
//				FQ_SRZM_2.setPicid(PicIdType.FQ_SRZM_2.getCode());
//			}
//			transferOtherAttachmentsParam.setAttachmentSort(AttachmentSort.YE_WU_FU_JIAN_DA_BAO.getCode());
//			transferOtherAttachmentsParam.setFileLabel(AttachmentLabel.YE_WU_FU_JIAN_DA_BAO.getCode());
//			TransferOtherAttachments FQ_QT_ZIP = transferOtherAttachmentsMapper.selectRefined(transferOtherAttachmentsParam);
//			if(!checkCompleted(FQ_QT_ZIP)){
//				throw new BasePartnerException(PartnerErrorCode.PIC_DIVI_MISSGING.getCode(), "【分期】其他图片(zip包的格式)缺失");
//			}
//			FQ_QT_ZIP.setPicid(PicIdType.FQ_QT_ZIP.getCode());
//			transferOtherAttachmentsParam.setAttachmentSort(AttachmentSort.ZHU_JIE_REN_QIAN_ZI.getCode());
//			transferOtherAttachmentsParam.setFileLabel(AttachmentLabel.ZHU_JIE_REN_QIAN_ZI_SHI_PIN.getCode());
//			TransferOtherAttachments FQ_SPMQSPZL = transferOtherAttachmentsMapper.selectRefined(transferOtherAttachmentsParam);
//			if(!checkCompleted(FQ_SPMQSPZL)){
//				throw new BasePartnerException(PartnerErrorCode.PIC_DIVI_MISSGING.getCode(), "【分期】视频面签视频资料缺失");
//			}
//			FQ_SPMQSPZL.setPicid(PicIdType.FQ_SPMQSPZL.getCode());
//			附件检查完成=============================
			
			TransferDzApplyDivi transferDzApplyDivi = new TransferDzApplyDivi();
			transferDzApplyDivi.setDpStatus(DpStatus.NORMAL.getCode());
			transferDzApplyDivi.setBankOrderNo(orderno);
			transferDzApplyDivi.setOrderSql("`CREATED` DESC");
			transferDzApplyDivi = transferDzApplyDiviMapper.selectRefined(transferDzApplyDivi);
			if(null == transferDzApplyDivi) {
				throw new BasePartnerException(PartnerErrorCode.RECORD_DIVI_MISSING.getCode(), PartnerErrorCode.RECORD_DIVI_MISSING.getName());
			}
			
			TransferYwBusinessLoan transferYwBusinessLoan = new TransferYwBusinessLoan();
			transferYwBusinessLoan.setDpStatus(DpStatus.NORMAL.getCode());
			transferYwBusinessLoan.setBusiId(busiId);
			transferYwBusinessLoan.setOrderSql("`CREATED` DESC");
			transferYwBusinessLoan = transferYwBusinessLoanMapper.selectRefined(transferYwBusinessLoan);
			if(null == transferYwBusinessLoan) {
				throw new BasePartnerException(PartnerErrorCode.RECORD_LOAN_MISSING.getCode(), PartnerErrorCode.RECORD_LOAN_MISSING.getName());
			}
			
			TransferYwBusinessBuyer transferYwBusinessBuyer = new TransferYwBusinessBuyer();
			transferYwBusinessBuyer.setDpStatus(DpStatus.NORMAL.getCode());
			transferYwBusinessBuyer.setBusiId(busiId);
			transferYwBusinessBuyer = transferYwBusinessBuyerMapper.selectRefined(transferYwBusinessBuyer);
			if(null == transferYwBusinessBuyer) {
				throw new BasePartnerException(PartnerErrorCode.RECORD_BUYER_MISSING.getCode(), PartnerErrorCode.RECORD_BUYER_MISSING.getName());
			}
			
			/**
			 * 组装分期参数
			 */
			ApplyDiviGeneralRequest request = new ApplyDiviGeneralRequest();
			PublicRequest pub = preparedDiviPub(orderno, zoneno, used ? "907" : "1");
			request.setPub(pub);
			
			ApplyDiviGeneralBaseInfo req = new ApplyDiviGeneralBaseInfo();
			
			ApplyDiviGeneralBusiInfo busi = new ApplyDiviGeneralBusiInfo(); 
			CarInfo car = new CarInfo();
			car.setCarType(transferYwBusinessCar.getNameCarModel());
			car.setPrice(transferYwBusinessCar.getPrice());
			car.setCarNo1(transferYwBusinessCar.getVin());
			car.setCarRegNo(transferDzApplyDivi.getRegistrationNumber());
			car.setShorp4s(transferDzApplyDivi.getDealerName());
			car.setCarNo2(transferDzApplyDivi.getLicensePlate());
			if(used) {
				car.setAssessPrice(transferYwBusinessCar.getEvaluatePrice());
				// update 2018-03-13 评估机构都直接为0
//				car.setAssessOrg(transferDzApplyDivi.getAssessOrg());
				car.setAssessOrg("0");
				car.setUsedYears(transferYwBusinessLoan.getCarAge());
			}
			busi.setCar(car);
			
			DiviInfo divi = new DiviInfo();
			divi.setPaidAmt(transferYwBusinessLoan.getFirstPaymentAmount());
//			@update2018-02-26 签约贷款额修改为实际贷款额
//			divi.setAmount(transferYwBusinessLoan.getSignLoanAmount());
			divi.setAmount(transferYwBusinessLoan.getLoanAmount());
			divi.setTerm(transferYwBusinessLoan.getLoanMonth());
//			@update2018-02-08
//			divi.setInterest(transferYwBusinessLoan.getCompanyRate() * 100);
			divi.setInterest(transferYwBusinessLoan.getBankRate() * 100);
			divi.setFeeMode(transferDzApplyDivi.getFeeMode());
			divi.setIsPawn("1");
			divi.setPawnGoods(transferYwBusinessCar.getVin() + transferYwBusinessCar.getNameCarModel());
			divi.setIsAssure("1");
			if(!used) {
				divi.setTiexiFlag(transferDzApplyDivi.getTiexiFlag());
				divi.setTiexiRate(transferDzApplyDivi.getTiexiRate());
			}
			divi.setCard(transferDzApplyDivi.getCard());
			busi.setDivi(divi);
			
			req.setBusi(busi);
			
			CustomerInfo customer = new CustomerInfo();
			customer.setCustName(transferYwBusinessBuyer.getName());
			customer.setIdType(CertificatesType.CERT_SFZ.getCode());
			customer.setIdNo(transferYwBusinessBuyer.getIdno());
			customer.setMobile(transferYwBusinessBuyer.getTel1());
			customer.setAddress(transferYwBusinessBuyer.getFamilyAddr());
			customer.setUnit(transferYwBusinessBuyer.getCompany());
			req.setCustomer(customer);
			
			req.setNote(transferDzApplyDivi.getRemarks());
			
			List<PicInfo> pics = new ArrayList<PicInfo>();
//			pics.add(getPicInfo(FQ_ZCDJ_1));
//			pics.add(getPicInfo(FQ_ZCDJ_2));
			pics.add(getPicInfo(FQ_ZJ_BRZM));
			pics.add(getPicInfo(FQ_ZJ_BRFM));
			if(null != FQ_ZJ_POZM) {
				pics.add(getPicInfo(FQ_ZJ_POZM));
			}
			if(null != FQ_ZJ_POFM) {
				pics.add(getPicInfo(FQ_ZJ_POFM));
			}
//			if(null != FQ_HYZM_JHZ) {
//				pics.add(getPicInfo(FQ_HYZM_JHZ));
//			}
//			if(null != FQ_HYZM_DSZM) {
//				pics.add(getPicInfo(FQ_HYZM_DSZM));
//			}
//			pics.add(getPicInfo(FQ_GCFP));
//			pics.addAll(getPicInfos(FQ_SMZP_1s));
//			pics.addAll(getPicInfos(FQ_KHQZ_1s));
//			pics.add(getPicInfo(FQ_HK_HKB_1));
//			pics.add(getPicInfo(FQ_HK_HKB_2));
//			pics.add(getPicInfo(FQ_HK_HKB_3));
//			pics.add(getPicInfo(FQ_SRZM_1));
//			if(null != FQ_SRZM_2) {
//				pics.add(getPicInfo(FQ_SRZM_2));
//			}
//			pics.add(getPicInfo(FQ_QT_ZIP));
//			pics.add(getPicInfo(FQ_SPMQSPZL));
			req.setPics(pics);
			
//			Integer applyDiviStatus = transferDzApplyDivi.getApplyDiviStatus();
//			String applyDiviFlag = null;
//			if(ApplyDiviStatus.ZAI_CI_TI_JIAO.getCode().equals(applyDiviStatus)) {
//				applyDiviFlag = "1";
//			} else {
//				applyDiviFlag = "0";
//			}
			
			String applyDiviFlag = transferDzApplyDivi.getApplyDiviFlag();
			applyDiviFlag = StringUtils.isBlank(applyDiviFlag) ? "0" : applyDiviFlag;
			req.setResubmit(applyDiviFlag);
			transferDzApplyDivi.setApplyDiviFlag(applyDiviFlag);
			
			request.setReq(req);
			
			boolean applyDiviGeneral = hzicbcService.applyDiviGeneral(request, hzicbcConfig.getPlatno());
			if(applyDiviGeneral) {
				transferDzApplyDivi.setApplyDiviFlag("1");
				transferDzApplyDivi.setTransferHandleStatus(TransferHandleStatus.FA_SONG_CHENG_GONG.getCode());
				transferDzApplyDiviService.updateJust(transferDzApplyDivi);
				
				newTransaction.saveAfterApplyDiviStatusHzicbc(orderno, busiId);
				//TODO 查询申请分期成功后推送面签多媒体到工行
//				newTransaction.saveSendMultiMediaUpload(orderno, busiId);
			} else {
				transferDzApplyDivi.setTransferHandleStatus(TransferHandleStatus.FA_SONG_SHI_BAI.getCode()); 
				Integer tryCount = transferDzApplyDivi.getTryCount();
				if(tryCount == null || tryCount < 10) {
					transferDzApplyDivi.setTryCount(tryCount == null ? 1 : tryCount + 1);
					newTransaction.saveApplyDiviHzicbcRetry(orderno, busiId); //10分钟
				} else {
					saveApplyDiviBack(orderno, "中间服务器调用分期次数超过10次", false);
				}
			}
			transferDzApplyDiviMapper.updateByPrimaryKeySelective(transferDzApplyDivi);
			return applyDiviGeneral;
		} catch (SystemException e) {
			newTransaction.saveApplyDiviHzicbcRetry(orderno, busiId); //10分钟
		} catch (ParamException e) {
			saveApplyDiviBack(orderno, e.getErrorMsg(), false);
		} catch (ProgramException e) {
			saveApplyDiviBack(orderno, e.getErrorMsg(), false);
		} catch (BasePartnerException e) { //附件列表不存在，或者文件没有下载好
			newTransaction.saveSynAttachementsDiepu(orderno, busiId);//2分钟
			newTransaction.saveFileDownloadQiniu(orderno, busiId);//5分钟
			newTransaction.saveApplyDiviHzicbcFirst(orderno, busiId);//30分钟
		} catch(Exception e){
			logger.error("HzicbcProxyServiceImpl.saveApplyDivi happend exception.params --> orderno is {}. exception is {}.", orderno, e);
			newTransaction.saveApplyDiviHzicbcFirst(orderno, busiId);//30分钟
		}
		return false;
	}
	
	
	
	
	
	
	
//	===================辅助方法================
	private String parseDescribe(FileListType fileListType) {
		String describe = "下载";
		switch (fileListType) {
		case FILE_KKQDWJ:
			describe += FileListType.FILE_KKQDWJ.getName();
			break;
		case FILE_WDYMXQDWJ:
			describe += FileListType.FILE_WDYMXQDWJ.getName();
			break;
		case FILE_YQCJQDWJ:
			describe += FileListType.FILE_YQCJQDWJ.getName();
			break;
		case FILE_YQCSQDWJ:
			describe += FileListType.FILE_YQCSQDWJ.getName();
			break;
		default:
			break;
		}
		return describe;
	}
	private String parsePath(FileListType fileListType) {
		String localPath = null;
		String basePath = fileProxyConfig.getBasePathNginx() + fileProxyConfig.getBasePathHzicbc();
		switch (fileListType) {
		case FILE_KKQDWJ:
			localPath = basePath + fileProxyConfig.getKaikaHzicbc();
			break;
		case FILE_WDYMXQDWJ:
			localPath = basePath + fileProxyConfig.getWeidiyaHzicbc();
			break;
		case FILE_YQCJQDWJ:
			localPath = basePath + fileProxyConfig.getCuijiaoHzicbc();
			break;
		case FILE_YQCSQDWJ:
			localPath = basePath + fileProxyConfig.getCuishouHzicbc();
			break;
		default:
			break;
		}
		if(StringUtils.isNotBlank(localPath)) {
			File folder = new File(localPath);
			if(!folder.exists()) {
				folder.mkdirs();
			}
		}
		return localPath;
	}
	/**
	 * 检查相片是否完整
	 * @param transferOtherAttachments
	 * @return
	 */
	private boolean checkCompleted(TransferOtherAttachments transferOtherAttachments) {
		if(null == transferOtherAttachments) { //未同步
			return false;
		}
		String localFilePath = transferOtherAttachments.getLocalFilePath();
		if(StringUtils.isBlank(localFilePath)) {
			return false;
		}
		String filePath = fileProxyConfig.getBasePathNginx() + transferOtherAttachments.getLocalFilePath();
		if(!new File(filePath).exists()) {
			return false;
		}
		return true;
	}
	@Override
	public boolean applyToIcbcOpenCard(String modeId,String dataId) {
		Integer tryCount=0;
		String busiId="";
		Date now = new Date();
		CreditCardApplyRequest request =new CreditCardApplyRequest();
		
		TransferYwOrdernoBank transferYwOrdernoBank = new TransferYwOrdernoBank();
		PublicResponse publicResponse=null;
		try {
			List<TransferYwOrdernoBank> transferYwOrdernoBankList = transferYwOrdernoBankService.getByBusiId(dataId);
			if(null != transferYwOrdernoBankList)
			{
				transferYwOrdernoBank = transferYwOrdernoBankList.get(0);
			}
		if(null == transferYwOrdernoBank || StringUtils.isBlank(transferYwOrdernoBank.getBusiId())) {
			throw new BasePartnerException(PartnerErrorCode.BUSI_ID_MISSING.getCode(), PartnerErrorCode.BUSI_ID_MISSING.getName());
		}
		
		TransferOtherAttachments transferOtherAttachmentsParam = new TransferOtherAttachments();
		transferOtherAttachmentsParam.setDpStatus(DpStatus.NORMAL.getCode());
		transferOtherAttachmentsParam.setDataid(dataId);
		transferOtherAttachmentsParam.setAttachmentSort(AttachmentSort.HZ_YIN_HANG_KAIKA_ZILIAO.getCode());
		transferOtherAttachmentsParam.setFileLabel(AttachmentLabel.KAI_KA_SHEN_QING_BIAO_WORD.getCode());
		TransferOtherAttachments attachments = transferOtherAttachmentsMapper.selectRefined(transferOtherAttachmentsParam);
		busiId=dataId;
		List<PicInfo> pics = new ArrayList<PicInfo>();
		if(!checkCompleted(attachments)){
			//写一个时间为2分钟（可配）只有的 从主程序获取附件列表 的定时任务；ScheduleProxyConfig
			newTransaction.getAttachments(transferYwOrdernoBank.getOrdeRno(), transferYwOrdernoBank.getBusiId(),DateUtil.increaseMinute(now, scheduleProxyConfig.getSynAttachementsDiepu() / 1000 / 60));
			//写一个时间为5分钟（可配）之后的下载附件定时任务；
			newTransaction.downLoadAttachments(transferYwOrdernoBank.getOrdeRno(), transferYwOrdernoBank.getBusiId(),DateUtil.increaseMinute(now, scheduleProxyConfig.getFileDownloadQiniu() / 1000 / 60));
			newTransaction.saveToHzicbc(transferYwOrdernoBank.getOrdeRno(),transferYwOrdernoBank.getBusiId(),DateUtil.increaseMinute(now, scheduleProxyConfig.getOpenCardSussess() / 1000 / 60));
			return false;
		} else {
			attachments.setPicid(PicIdType.KK_KKSQB_SFZZFM.getCode());
			pics.add(getPicInfo(attachments));
		}
		
		
		transferOtherAttachmentsParam=new TransferOtherAttachments();
		transferOtherAttachmentsParam.setDpStatus(DpStatus.NORMAL.getCode());
		transferOtherAttachmentsParam.setDataid(dataId);
		transferOtherAttachmentsParam.setAttachmentSort(AttachmentSort.HZ_YIN_HANG_KAIKA_ZILIAO.getCode());
		transferOtherAttachmentsParam.setFileLabel(AttachmentLabel.EDU_HEDING_SQBIAO.getCode());
		TransferOtherAttachments attachments1 = transferOtherAttachmentsMapper.selectRefined(transferOtherAttachmentsParam);
		if(!checkCompleted(attachments1)){
			//写一个时间为2分钟（可配）只有的 从主程序获取附件列表 的定时任务；ScheduleProxyConfig
			newTransaction.getAttachments(transferYwOrdernoBank.getOrdeRno(), transferYwOrdernoBank.getBusiId(),DateUtil.increaseMinute(now, scheduleProxyConfig.getSynAttachementsDiepu() / 1000 / 60));
			//写一个时间为5分钟（可配）之后的下载附件定时任务；
			newTransaction.downLoadAttachments(transferYwOrdernoBank.getOrdeRno(), transferYwOrdernoBank.getBusiId(),DateUtil.increaseMinute(now, scheduleProxyConfig.getFileDownloadQiniu() / 1000 / 60));
			newTransaction.saveToHzicbc(transferYwOrdernoBank.getOrdeRno(),transferYwOrdernoBank.getBusiId(),DateUtil.increaseMinute(now, scheduleProxyConfig.getOpenCardSussess() / 1000 / 60));
			return false;
		} else {
			attachments1.setPicid(PicIdType.KK_ZXEDHDSQB.getCode());
			pics.add(getPicInfo(attachments1));
		}
		if(attachments1!=null && attachments!=null){
			CreditCardApplyInfo req=new CreditCardApplyInfo();
			req.setPics(pics);
			
			PublicRequest pub = preparedPub(transferYwOrdernoBank.getOrdeRno(), transferYwOrdernoBank.getAreaId());
			request.setPub(pub);
			
			TransferYwBusinessLoan transferYwBusinessLoan=new TransferYwBusinessLoan();
			transferYwBusinessLoan.setDpStatus(DpStatus.NORMAL.getCode());
			transferYwBusinessLoan.setBusiId(dataId);
			transferYwBusinessLoan.setOrderSql("`CREATED` DESC");
			transferYwBusinessLoan=transferYwBusinessLoanMapper.selectRefined(transferYwBusinessLoan);
			LoanInfo loaninfo=new LoanInfo();
			if(transferYwBusinessLoan!=null){
				loaninfo.setLoanamount(transferYwBusinessLoan.getLoanAmount()==null?0.0:transferYwBusinessLoan.getLoanAmount());
				loaninfo.setTerm(transferYwBusinessLoan.getLoanMonth()==null?0:transferYwBusinessLoan.getLoanMonth());
				loaninfo.setFeeratio(transferYwBusinessLoan.getBankRate()==null?0.0:transferYwBusinessLoan.getBankRate()*100);
				loaninfo.setFeeamount(transferYwBusinessLoan.getStagesFee()==null?0.0:transferYwBusinessLoan.getStagesFee());
				loaninfo.setCarprice(transferYwBusinessLoan.getCarPrice()==null?0.0:transferYwBusinessLoan.getCarPrice());
				Double loanAmount = Optional.ofNullable(transferYwBusinessLoan).map(item -> item.getLoanAmount()).orElse(0.0);
				Double carPrice = Optional.ofNullable(transferYwBusinessLoan).map(item -> item.getCarPrice()).orElse(null);
				if(null == carPrice) {
					ExceptionHelper.thow(ResultCode.FAIL_PARAM_EMPTY.getCode().toString(),"车价不能为空");
				}
				String sss=String.valueOf((loanAmount/carPrice*100));
				if(sss.contains(".")){
					loaninfo.setLoanratio(sss.substring(0,sss.indexOf(".")));
				}else{
					loaninfo.setLoanratio(sss);
				}
				req.setLoaninfo(loaninfo);
			}
			//查询性别
			TransferYwBusinessBuyer transferYwBusinessBuyer=new TransferYwBusinessBuyer();
			transferYwBusinessBuyer.setCarManType(CreditPeopleType.ZHU_JIE_REN.getCode());
			transferYwBusinessBuyer.setBusiId(dataId);
			transferYwBusinessBuyer=transferYwBusinessBuyerMapper.selectRefined(transferYwBusinessBuyer);
			String sex="01";
//			String unitname="";
			if(transferYwBusinessBuyer!=null){
				sex=transferYwBusinessBuyer.getSex();
//				unitname=transferYwBusinessBuyer.getCompany();
			}
			
			TransferYwOpenCardHzicbcSub transferYwOpenCardHzicbcSub=new TransferYwOpenCardHzicbcSub();
			transferYwOpenCardHzicbcSub.setBusiId(transferYwOrdernoBank.getBusiId());
			transferYwOpenCardHzicbcSub.setDpStatus(DpStatus.NORMAL.getCode()); //过滤正常数据  2018-03-09 xiongxiaotun
			transferYwOpenCardHzicbcSub=transferYwOpenCardHzicbcSubMapper.selectRefined(transferYwOpenCardHzicbcSub);
			if(transferYwOpenCardHzicbcSub!=null){
//				req.setDscode("1");//营销代码
//				req.setDrawzono("1");//领卡地区号
//				req.setDrawbrno("1");//领卡网点号
				req.setReltsex1(transferYwOpenCardHzicbcSub.getReltsex1());
				req.setReltsex2(transferYwOpenCardHzicbcSub.getReltsex2());
				req.setCustsort("000");//证件类型
				req.setCustcode(transferYwOpenCardHzicbcSub.getCustcode());//证件号码
				req.setChnsname(transferYwOpenCardHzicbcSub.getChnsname());//姓名
				req.setEngname(transferYwOpenCardHzicbcSub.getEngname());//姓名拼音或英文名
				req.setSex(sex.equals("01")?"1":"2");//性别
				req.setMrtlstat(transferYwOpenCardHzicbcSub.getMrtlstat());//婚姻状况
				req.setBirthdate(new SimpleDateFormat("yyyy-MM-dd").format(transferYwOpenCardHzicbcSub.getBirthdate()).replaceAll("-", "") );//出生日期
				req.setEdulvl(transferYwOpenCardHzicbcSub.getEdulvl());//教育程度
				req.setHomestat(transferYwOpenCardHzicbcSub.getHomestat());//住宅状况
				req.setHadrchoic("3");//住宅地址选择
				req.setHprovince(transferYwOpenCardHzicbcSub.getHprovince());//住宅地址省份
				req.setHcity(transferYwOpenCardHzicbcSub.getHcity());//住宅地址市
				req.setHcounty(transferYwOpenCardHzicbcSub.getHcounty());//住宅地址县
				req.setHaddress(transferYwOpenCardHzicbcSub.getHaddress());//住宅地址
//				req.setHaddrid("123");//住宅地址ID
				req.setHomezip(transferYwOpenCardHzicbcSub.getHomezip());//住宅邮编
				req.setHphonzono("0");//住宅电话号码
//				req.setHphonext("111");//住宅电话分机
				req.setMblchoic("3");//手机选择
				req.setMvblno(transferYwOpenCardHzicbcSub.getMvblno());//手机号码
//				req.setMblid("1");//手机ID
//				req.setUnitname(unitname);//工作单位
				req.setUnitname(transferYwOpenCardHzicbcSub.getCcol1());//工作单位 从ccol1 2018-03-09 xiongxiaotun
				req.setCophozono("0");//单位电话区号
				req.setCophoneno("0");//单位电话号码
				req.setCophonext("0");//单位电话分机
				req.setCadrchoic("3");//单位地址选择
				req.setCprovince(transferYwOpenCardHzicbcSub.getCprovince());//单位地址省份
				req.setCcity(transferYwOpenCardHzicbcSub.getCcity());//单位地址市
				req.setCcounty(transferYwOpenCardHzicbcSub.getCcounty());//单位地址县
				req.setCaddress(transferYwOpenCardHzicbcSub.getCaddress());//工作单位地址
//				req.setCaddrid("123");//单位地址ID
				req.setCorpzip(transferYwOpenCardHzicbcSub.getCorpzip());//单位邮编
				Integer yearincome = transferYwOpenCardHzicbcSub.getYearincome();
				req.setYearincome(yearincome == null ? "" : yearincome.toString());//本人年收入
				req.setModelcode(transferYwOpenCardHzicbcSub.getModelcode());//单位性质
				req.setOccptn(transferYwOpenCardHzicbcSub.getOccptn());//职业
				req.setComchoic("3");//通讯地址选择
				req.setCommprov(transferYwOpenCardHzicbcSub.getCommprov());//通讯地址省份
				req.setCommcity(transferYwOpenCardHzicbcSub.getCommcity());//通讯地址市
				req.setCommcounty(transferYwOpenCardHzicbcSub.getCommcounty());//通讯地址县
				req.setCommaddr(transferYwOpenCardHzicbcSub.getCommaddr());//通讯地址
//				req.setCommaddrid("12");//通讯地址ID
				req.setCommazip(transferYwOpenCardHzicbcSub.getCommazip());//通讯地址邮编
				req.setReltname1(transferYwOpenCardHzicbcSub.getReltname1());//联系人一姓名
				req.setReltsex1(transferYwOpenCardHzicbcSub.getReltsex1());//联系人一性别
				req.setReltship1(transferYwOpenCardHzicbcSub.getReltship1());//联系人一与主卡申请关系
				req.setReltmobl1(transferYwOpenCardHzicbcSub.getReltmobl1());//联系人一手机
//				req.setReltphzon1("0571");//联系人一联系电话区
				req.setRelaphone1("0");//联系人一联系电话号
//				req.setReltphext1("46782488");//联系人一联系电话分
				req.setReltname2(transferYwOpenCardHzicbcSub.getReltname2());
				req.setReltsex2(transferYwOpenCardHzicbcSub.getReltsex2());//联系人一性别
				req.setReltship2(transferYwOpenCardHzicbcSub.getReltship2());//联系人一与主卡申请关系
				req.setReltmobl2(transferYwOpenCardHzicbcSub.getReltmobl2());//联系人一手机
//				req.setRtcophzn2("0571");//联系人一联系电话区
				req.setRtcophon2("0");//联系人一联系电话号
//				req.setRtcophet2("46782488");//联系人一联系电话分
//				req.setCardkind("0");//申请卡种
//				req.setCardlogo("1");//申请品牌
//				req.setCardtype("1");//申请卡类
//				req.setCardmedm("1");//卡片介质
//				req.setAllyno("1");//联名编号
//				req.setAlmebno("001");//联名单位会员号
				req.setFcurrtyp("001");//币种
//				req.setExpdate("1");//有效期
//				req.setFeeflag("1");//年费标志
//				req.setFrfeeflag("1");//免年费标志
				req.setAccgetm(transferYwOpenCardHzicbcSub.getAccgetm());//对帐单寄送方式
				req.setAccaddrf(transferYwOpenCardHzicbcSub.getAccaddrf());//对帐单寄送地址
//				req.setRmbcred("10000000");//申请本币额度
				req.setMamobile(transferYwOpenCardHzicbcSub.getMamobile());//主卡发送移动电话
				req.setSmsphone(transferYwOpenCardHzicbcSub.getSmsphone());//发送短信帐单手机号码
//				req.setQesno("1");//问题编号
//				req.setAnswer("1");//问题答案
//				req.setCrdrflag("1");//产品标志
				req.setAuthref(transferYwOpenCardHzicbcSub.getAuthref());//发证机关
				String statdate = transferYwOpenCardHzicbcSub.getStatdate();
				//req.setStatdate(DateUtil.dateTo8Str(statdate));//证件有效期
				req.setStatdate(statdate);//证件有效期
				String indate = transferYwOpenCardHzicbcSub.getIndate();
				req.setIndate(DateUtil.dateTo8Str(DateUtil.StringToDate(indate)));//何时入住现址
				Date joindate = transferYwOpenCardHzicbcSub.getJoindate();
				req.setJoindate(null == joindate ? null : new SimpleDateFormat("yyyy-MM").format(joindate).replaceAll("-", ""));//进入单位时间
//				req.setReltno("1");//关系账号
//				req.setCardbin("1");//申请卡BIN
				req.setDrawmode(transferYwOpenCardHzicbcSub.getDrawmode());//卡片领取方式
				req.setDrawaddr(transferYwOpenCardHzicbcSub.getDrawaddr());//卡片寄送地址类型
//				req.setSaleno("1");//营销档案编号
				req.setMachgf(transferYwOpenCardHzicbcSub.getMachgf());//主卡开通余额变动提醒
				req.setMachgmobile(transferYwOpenCardHzicbcSub.getMachgmobile());//主卡余额提醒发送手机号码
				req.setEmladdrf(transferYwOpenCardHzicbcSub.getEmladdrf());//开通email对账单
//				req.setPostxflg("1");//POS转帐标志
//				req.setSlftxflg("1");//自助终端转帐标志
//				req.setAtmtxflg("1");//ATM转帐标志
//				req.setDdtrxtype("1");//自动还款交易类型
				req.setStmtemail(transferYwOpenCardHzicbcSub.getStmtemail());//对帐单EMAIL
				req.setOutacctype1(transferYwOpenCardHzicbcSub.getOutacctype());//自动还款转出帐户类型1
				req.setOutcardno1(transferYwOpenCardHzicbcSub.getOutcardno1());//转出卡号/帐号1
				req.setDdamttype1("0");//还款金额类型1
				req.setOutacctype2("1");//自动还款转出帐户类型2
//				req.setOutcardno2("25441654");//转出卡号/帐号2
				req.setDdamttype2("0");//还款金额类型2
//				req.setPaydays(transferYwOpenCardHzicbcSub.getPaydays().toString());//提前还款天数
				Integer paydays = transferYwOpenCardHzicbcSub.getPaydays();
				if(null != paydays) {
					req.setPaydays(paydays.toString());//提前还款天数
				}
//				req.setFftrxtype("1");//同步签订外币自动还款
				req.setEcshflag("1");//电子现金标志
//				req.setAppkind("1");//申请渠道
//				req.setCreditcardno("11111111");//产品编号
//				req.setProdname("12313");//产品简称
//				req.setFeatgype("123");//产品特色类别
//				req.setFeatname("111");//产品特色名称
//				req.setFakaorg("111");//所属发卡机构名称
				req.setHphoneno("0" );//住宅电话号码
			}
			request.setReq(req);
			
			com.icbc.api.core.ApiResponse result=hzicbcService.creditCardApply(request, hzicbcConfig.getPlatno());
			if(result != null) {
			Map<Object, Object> pubResult = result.getMap("pub");
			if(null != pub) {
				publicResponse = JSON.parseObject(JSON.toJSONString(pubResult), PublicResponse.class);
				if(null == publicResponse) {
					return false;
				}
				String retcode = publicResponse.getRetcode();
				if(StringUtils.isBlank(retcode)) {
					return false;
				}
				TransferYwOpenCardHzicbc transferYwOpenCardHzicbc=new TransferYwOpenCardHzicbc();
				transferYwOpenCardHzicbc.setBusiId(dataId);
				transferYwOpenCardHzicbc=transferYwOpenCardHzicbcMapper.selectRefined(transferYwOpenCardHzicbc);
				if(transferYwOpenCardHzicbc!=null){
					if(retcode.startsWith(ReturnCodePrefixType.SUCCESS.getCode())){
						transferYwOpenCardHzicbc.setTransferHandleStatus(TransferHandleStatus.FA_SONG_CHENG_GONG.getCode());
						transferYwOpenCardHzicbcMapper.updateByPrimaryKeySelective(transferYwOpenCardHzicbc);
					}else{
						if(!retcode.equals(ReturnCodePrefixType.REPEAT_DATA.getCode())){
							transferYwOpenCardHzicbc.setTransferHandleStatus(TransferHandleStatus.FA_SONG_SHI_BAI.getCode());
							transferYwOpenCardHzicbcMapper.updateByPrimaryKeySelective(transferYwOpenCardHzicbc);
							if(retcode.startsWith(ReturnCodePrefixType.FAIL_YQCJQDWJ.getCode()) ) {
								Integer tryCount1 =transferYwOpenCardHzicbc.getTryCount();
								if(tryCount1<10){
									newTransaction.saveToHzicbc(transferYwOrdernoBank.getOrdeRno(),busiId,DateUtil.increaseMinute(now, scheduleProxyConfig.getOpenCardSussess() / 1000 / 60));
									transferYwOpenCardHzicbc.setTryCount(tryCount1+1);
									transferYwOpenCardHzicbcMapper.updateByPrimaryKeySelective(transferYwOpenCardHzicbc);
								}else{
									//调用主程序开卡退回接口
									saveBackReasonInterface(publicResponse,busiId);
								}
							}else {
//							//调用主程序开卡退回接口
								saveBackReasonInterface(publicResponse,busiId);
							}
						}
					}
				}
				SysUserProxy sysUserProxy=new SysUserProxy();
				sysUserProxy.setUserId(TransferHandleStatus.FAN_HUI_CHENG_GONG.getCode().toString());
				sysUserProxy.setLoginName(TransferHandleStatus.FAN_HUI_CHENG_GONG.getValue());
				
				TransferLogs transferLogs=new TransferLogs();
				transferLogs.setBankOrderNo(transferYwOrdernoBank.getOrdeRno());
				transferLogs.setBusiId(busiId);
				transferLogs.setTransferModeId(modeId);
				
				TransferLogsSub transferLogsSub=new TransferLogsSub();
				transferLogsSub.setBusiId(busiId);
				transferLogsSub.setTransferModeId(modeId);
				transferLogsSub.setResponseMessageEvent(publicResponse.getRetcode()+":"+publicResponse.getRetmsg());
				transferLogsSub.setRequestMessageEvent(JSON.toJSONString(request.getReq()));
				logsBiz.diepuLogs(sysUserProxy, transferLogs, transferLogsSub);
			}
		}
		}
		}catch (BasePartnerException e) {
			SysUserProxy sysUserProxy=new SysUserProxy();
			sysUserProxy.setUserId(TransferHandleStatus.FA_SONG_SHI_BAI.getCode().toString());
			sysUserProxy.setLoginName(TransferHandleStatus.FA_SONG_SHI_BAI.getValue());
			
			TransferLogs transferLogs=new TransferLogs();
			transferLogs.setBankOrderNo(null != transferYwOrdernoBank ? transferYwOrdernoBank.getOrdeRno() : null);
			transferLogs.setBusiId(busiId);
			transferLogs.setTransferModeId(modeId);
			
			TransferLogsSub transferLogsSub=new TransferLogsSub();
			transferLogsSub.setBusiId(busiId);
			transferLogsSub.setTransferModeId(modeId);
			String errorMsg = e.getErrorMsg();
			transferLogsSub.setResponseMessageEvent(errorMsg);
			transferLogsSub.setRequestMessageEvent(JSON.toJSONString(request.getReq()));
			logsBiz.diepuLogs(sysUserProxy, transferLogs, transferLogsSub);
			if(tryCount<10){
				newTransaction.saveToHzicbc(dataId,busiId,DateUtil.increaseMinute(now, scheduleProxyConfig.getOpenCardSussess() / 1000 / 60));
			}
			logger.error("HzicbcProxyServiceImpl.applyToIcbcOpenCard happend exception.params --> modeId is {}. exception is {}.", modeId, e);
		} 
		catch(Exception e){
			logger.error("HzicbcProxyServiceImpl.applyToIcbcOpenCard happend exception.params --> modeId is {}. exception is {}.", modeId, e);
//			如果重发次数小于10，写一条10分钟之后的【向工行申请开卡】定时任务，重发次数+1；
			if(tryCount<10){
				newTransaction.saveToHzicbc(transferYwOrdernoBank.getOrdeRno(),busiId,DateUtil.increaseMinute(now, scheduleProxyConfig.getOpenCardSussess() / 1000 / 60));
			}
			SysUserProxy sysUserProxy=new SysUserProxy();
			sysUserProxy.setUserId(TransferHandleStatus.FA_SONG_SHI_BAI.getCode().toString());
			sysUserProxy.setLoginName(TransferHandleStatus.FA_SONG_SHI_BAI.getValue());
			
			TransferLogs transferLogs=new TransferLogs();
			transferLogs.setBankOrderNo(null != transferYwOrdernoBank ? transferYwOrdernoBank.getOrdeRno() : null);
			transferLogs.setBusiId(busiId);
			transferLogs.setTransferModeId(modeId);
			
			TransferLogsSub transferLogsSub=new TransferLogsSub();
			transferLogsSub.setBusiId(busiId);
			transferLogsSub.setTransferModeId(modeId);
			transferLogsSub.setResponseMessageEvent(e.getMessage().length()>200?e.getMessage().substring(0,200):e.getMessage());
			transferLogsSub.setRequestMessageEvent(JSON.toJSONString(request.getReq()));
			logsBiz.diepuLogs(sysUserProxy, transferLogs, transferLogsSub);
		}
		return true;
	}

	private void saveBackReasonInterface(PublicResponse publicResponse,String busiId) throws BasePartnerException {
		OpenCardbackReasonRequest req1=new OpenCardbackReasonRequest();
		req1.setBusiId(busiId);
		req1.setBacknote(publicResponse.getRetmsg());
		diepuService.openCardBackReason(req1);
		
	}

	@Override
	public boolean diepuQueryOpenCardCourse(String modeId, String datasId) {
		TransferYwOrdernoBank transferYwOrdernoBank=null;
		transferYwOrdernoBank = transferYwOrdernoBankService.getByBusiId(datasId).get(0);
		if(null == transferYwOrdernoBank || StringUtils.isBlank(transferYwOrdernoBank.getBusiId())) {
			ExceptionHelper.thow(PartnerErrorCode.BUSI_MISSING.getCode().toString(), PartnerErrorCode.BUSI_MISSING.getName());
		}
		String busiId=transferYwOrdernoBank.getBusiId();
		CreditStatusRequest request = new CreditStatusRequest();
		PublicRequest pub = preparedPub(transferYwOrdernoBank.getOrdeRno(), transferYwOrdernoBank.getAreaId());
		request.setPub(pub);
		CreditStatusInfo creditStatusInfo=hzicbcService.applyCreditStatus(request, hzicbcConfig.getPlatno());
		
		String status = creditStatusInfo.getStatus();
		String notes = creditStatusInfo.getNotes();
		String updatetime = creditStatusInfo.getUpdatetime();
		
		DiepuYwOpenCardHzicbcRequest diepuYwOpenCardHzicbcRequest=new DiepuYwOpenCardHzicbcRequest();
		diepuYwOpenCardHzicbcRequest.setBusiId(busiId);
		diepuYwOpenCardHzicbcRequest.setHzicbcOpenCardStatus(creditStatusInfo.getStatus());
		diepuYwOpenCardHzicbcRequest.setHzicbcOpenCardStatusNote(creditStatusInfo.getNotes());
		diepuYwOpenCardHzicbcRequest.setHzicbcOpenCardStatusTime(creditStatusInfo.getUpdatetime());
		boolean flag=false;
		Date now = new Date();
		try {
			flag = diepuService.updateOpenCardStatus(diepuYwOpenCardHzicbcRequest);
		
			//返回成功后更新中转开卡表的数据
			if(flag){
				TransferYwOpenCardHzicbc transferYwOpenCardHzicbcParam=new TransferYwOpenCardHzicbc();
				transferYwOpenCardHzicbcParam.setBusiId(busiId);
				transferYwOpenCardHzicbcParam.setDpStatus(DpStatus.NORMAL.getCode());
				TransferYwOpenCardHzicbc dbTransferYwOpenCardHzicbc=transferYwOpenCardHzicbcMapper.selectRefined(transferYwOpenCardHzicbcParam);
				if(dbTransferYwOpenCardHzicbc==null){
					ExceptionHelper.thow(PartnerErrorCode.BUSI_MISSING.getCode().toString(), PartnerErrorCode.BUSI_MISSING.getName());
				}
				
				TransferYwOpenCardHzicbc transferYwOpenCardHzicbc=new TransferYwOpenCardHzicbc();
				transferYwOpenCardHzicbc.setId(dbTransferYwOpenCardHzicbc.getId());
				transferYwOpenCardHzicbc.initUpdateData(TransferModeID.CHA_XUN_KAI_KA_JIN_DU.getCode(), TransferModeID.CHA_XUN_KAI_KA_JIN_DU.getValue());
				transferYwOpenCardHzicbc.setHzicbcOpenCardStatus(status);
				transferYwOpenCardHzicbc.setHzicbcOpenCardStatusNote(notes);
				transferYwOpenCardHzicbc.setHzicbcOpenCardStatusTime(updatetime);
				transferYwOpenCardHzicbcMapper.updateByPrimaryKeySelective(transferYwOpenCardHzicbc);
				
				if(("00").equals(status)|| ("10").equals(status) || ("11").equals(status)|| ("14").equals(status)){
					newTransaction.queryOpenCardCourse(transferYwOrdernoBank.getOrdeRno(), busiId, DateUtil.increaseMinute(now, scheduleProxyConfig.getOpenCardStatus() / 1000 / 60));
				}
				return true;
			} else {
				newTransaction.queryOpenCardCourse(transferYwOrdernoBank.getOrdeRno(), busiId, DateUtil.increaseMinute(now, scheduleProxyConfig.getOpenCardStatus() / 1000 / 60));
			}
		} catch (BasePartnerException e) {
			newTransaction.queryOpenCardCourse(transferYwOrdernoBank.getOrdeRno(), busiId, DateUtil.increaseMinute(now, scheduleProxyConfig.getOpenCardStatus() / 1000 / 60));
		} catch(Exception e) {
			logger.error("HzicbcProxyServiceImpl.diepuQueryOpenCardCourse happend exception.params --> modeId is {}, datasId[busiid] is {}. exception is {}.", modeId,datasId, e);
			newTransaction.queryOpenCardCourse(transferYwOrdernoBank.getOrdeRno(), busiId, DateUtil.increaseMinute(now, scheduleProxyConfig.getOpenCardStatus() / 1000 / 60));
		}
		return false;
		
	}
}
